You are here

public function XmlSitemapGenerator::setMemoryLimit in XML sitemap 2.x

Same name and namespace in other branches
  1. 8 src/XmlSitemapGenerator.php \Drupal\xmlsitemap\XmlSitemapGenerator::setMemoryLimit()

Calculate the optimal memory level for sitemap generation.

Parameters

int $new_limit: An optional PHP memory limit in bytes. If not provided, the value of getOptimalMemoryLimit() will be used.

Overrides XmlSitemapGeneratorInterface::setMemoryLimit

1 call to XmlSitemapGenerator::setMemoryLimit()
XmlSitemapGenerator::regenerateBefore in src/XmlSitemapGenerator.php
Perform operations before rebuilding the sitemap.

File

src/XmlSitemapGenerator.php, line 238

Class

XmlSitemapGenerator
XmlSitemap generator service class.

Namespace

Drupal\xmlsitemap

Code

public function setMemoryLimit($new_limit = NULL) {
  $current_limit = @ini_get('memory_limit');
  if ($current_limit && $current_limit != -1) {
    if (!is_null($new_limit)) {
      $new_limit = $this
        ->getOptimalMemoryLimit();
    }
    if (Bytes::toInt($current_limit) < $new_limit) {
      return @ini_set('memory_limit', $new_limit);
    }
  }
}