You are here

protected function MigrationBase::memoryExceeded in Migrate 7.2

Same name and namespace in other branches
  1. 6.2 includes/base.inc \MigrationBase::memoryExceeded()

Test whether we've exceeded the desired memory threshold. If so, output a message.

Return value

boolean TRUE if the threshold is exceeded, FALSE if not.

1 call to MigrationBase::memoryExceeded()
Migration::checkStatus in includes/migration.inc
Standard top-of-loop stuff, common between rollback and import - check for exceptional conditions, and display feedback.

File

includes/base.inc, line 1199
Defines the base class for migration processes.

Class

MigrationBase
The base class for all objects representing distinct steps in a migration process. Most commonly these will be Migration objects which actually import data from a source into a Drupal destination, but by deriving classes directly from MigrationBase…

Code

protected function memoryExceeded() {
  $usage = memory_get_usage();
  $pct_memory = $usage / $this->memoryLimit;
  if ($pct_memory > $this->memoryThreshold) {
    self::displayMessage(t('Memory usage is !usage (!pct% of limit !limit), resetting statics', array(
      '!pct' => round($pct_memory * 100),
      '!usage' => format_size($usage),
      '!limit' => format_size($this->memoryLimit),
    )), 'warning');

    // First, try resetting Drupal's static storage - this frequently releases
    // plenty of memory to continue
    drupal_static_reset();
    $usage = memory_get_usage();
    $pct_memory = $usage / $this->memoryLimit;

    // Use a lower threshold - we don't want to be in a situation where we keep
    // coming back here and trimming a tiny amount
    if ($pct_memory > 0.9 * $this->memoryThreshold) {
      self::displayMessage(t('Memory usage is now !usage (!pct% of limit !limit), not enough reclaimed, starting new batch', array(
        '!pct' => round($pct_memory * 100),
        '!usage' => format_size($usage),
        '!limit' => format_size($this->memoryLimit),
      )), 'warning');
      return TRUE;
    }
    else {
      self::displayMessage(t('Memory usage is now !usage (!pct% of limit !limit), reclaimed enough, continuing', array(
        '!pct' => round($pct_memory * 100),
        '!usage' => format_size($usage),
        '!limit' => format_size($this->memoryLimit),
      )), 'warning');
      return FALSE;
    }
  }
  else {
    return FALSE;
  }
}