function MigrateExecutable::memoryExceeded

Same name in other branches
  1. 9 core/modules/migrate/src/MigrateExecutable.php \Drupal\migrate\MigrateExecutable::memoryExceeded()
  2. 10 core/modules/migrate/src/MigrateExecutable.php \Drupal\migrate\MigrateExecutable::memoryExceeded()
  3. 11.x 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.

2 calls to MigrateExecutable::memoryExceeded()
MigrateExecutable::checkStatus in core/modules/migrate/src/MigrateExecutable.php
Checks for exceptional conditions, and display feedback.
TestMigrateExecutable::memoryExceeded in core/modules/migrate/tests/src/Unit/TestMigrateExecutable.php
Allows access to the protected memoryExceeded method.
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 479

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' => $this->formatSize($usage),
            '@limit' => $this->formatSize($this->memoryLimit),
        ]), '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' => $this->formatSize($usage),
                '@limit' => $this->formatSize($this->memoryLimit),
            ]), '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' => $this->formatSize($usage),
                '@limit' => $this->formatSize($this->memoryLimit),
            ]), 'warning');
            return FALSE;
        }
    }
    else {
        return FALSE;
    }
}

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