function MigrateExecutable::memoryExceeded

Same name in other branches
  1. 9 core/modules/migrate/src/MigrateExecutable.php \Drupal\migrate\MigrateExecutable::memoryExceeded()
  2. 8.9.x core/modules/migrate/src/MigrateExecutable.php \Drupal\migrate\MigrateExecutable::memoryExceeded()
  3. 10 core/modules/migrate/src/MigrateExecutable.php \Drupal\migrate\MigrateExecutable::memoryExceeded()

Tests whether we've exceeded the desired memory threshold.

If so, output a message.

Return value

bool TRUE if the threshold is exceeded, otherwise FALSE.

1 call to MigrateExecutable::memoryExceeded()
MigrateExecutable::checkStatus in core/modules/migrate/src/MigrateExecutable.php
Checks for exceptional conditions, and display feedback.
1 method overrides MigrateExecutable::memoryExceeded()
TestMigrateExecutable::memoryExceeded in core/modules/migrate/tests/src/Unit/TestMigrateExecutable.php
Allows access to the protected memoryExceeded method.

File

core/modules/migrate/src/MigrateExecutable.php, line 536

Class

MigrateExecutable
Defines a migrate executable class.

Namespace

Drupal\migrate

Code

protected function memoryExceeded() {
    $usage = $this->getMemoryUsage();
    $pct_memory = $usage / $this->memoryLimit;
    if (!($threshold = $this->memoryThreshold)) {
        return FALSE;
    }
    if ($pct_memory > $threshold) {
        $this->message
            ->display($this->t('Memory usage is @usage (@pct% of limit @limit), reclaiming memory.', [
            '@pct' => round($pct_memory * 100),
            '@usage' => ByteSizeMarkup::create($usage, NULL, $this->stringTranslation),
            '@limit' => ByteSizeMarkup::create($this->memoryLimit, NULL, $this->stringTranslation),
        ]), 'warning');
        $usage = $this->attemptMemoryReclaim();
        $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 * $threshold) {
            $this->message
                ->display($this->t('Memory usage is now @usage (@pct% of limit @limit), not enough reclaimed, starting new batch', [
                '@pct' => round($pct_memory * 100),
                '@usage' => ByteSizeMarkup::create($usage, NULL, $this->stringTranslation),
                '@limit' => ByteSizeMarkup::create($this->memoryLimit, NULL, $this->stringTranslation),
            ]), 'warning');
            return TRUE;
        }
        else {
            $this->message
                ->display($this->t('Memory usage is now @usage (@pct% of limit @limit), reclaimed enough, continuing', [
                '@pct' => round($pct_memory * 100),
                '@usage' => ByteSizeMarkup::create($usage, NULL, $this->stringTranslation),
                '@limit' => ByteSizeMarkup::create($this->memoryLimit, NULL, $this->stringTranslation),
            ]), 'warning');
            return FALSE;
        }
    }
    else {
        return FALSE;
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.