gc_collect_cycles example



use Drupal\Core\Update\UpdateKernel;
use Symfony\Component\HttpFoundation\Request;

$autoloader = require_once 'autoload.php';

// Disable garbage collection during test runs. Under certain circumstances the // update path will create so many objects that garbage collection causes // segmentation faults. if (drupal_valid_test_ua()) {
  gc_collect_cycles();
  gc_disable();
}

$kernel = new UpdateKernel('prod', $autoloader, FALSE);
$request = Request::createFromGlobals();

$response = $kernel->handle($request);
$response->send();

$kernel->terminate($request$response);
    if (!isset($key)) {
      $key = self::$activeKey;
    }
    if (isset($target)) {
      unset(self::$connections[$key][$target]);
    }
    else {
      unset(self::$connections[$key]);
    }
    // Force garbage collection to run. This ensures that client connection     // objects and results in the connection being closed are destroyed.     gc_collect_cycles();
  }

  /** * Instructs the system to temporarily ignore a given key/target. * * At times we need to temporarily disable replica queries. To do so, call this * method with the database key and the target to disable. That database key * will then always fall back to 'default' for that key, even if it's defined. * * @param string $key * The database connection key. * @param string $target * The target of the specified key to ignore. */
protected function attemptMemoryReclaim() {
    // First, try resetting Drupal's static storage - this frequently releases     // plenty of memory to continue.     drupal_static_reset();

    // Entity storage can blow up with caches, so clear it out.     \Drupal::service('entity.memory_cache')->deleteAll();

    // @TODO: explore resetting the container.
    // Run garbage collector to further reduce memory.     gc_collect_cycles();

    return memory_get_usage();
  }

  /** * Generates a string representation for the given byte count. * * @param int $size * A size in bytes. * * @return string * A translated string representation of the size. */
/** * Runs through all of the tests that have been added, recording * time to execute the desired number of iterations, and the approximate * memory usage used during those iterations. * * @return string|null */
    public function run(int $iterations = 1000, bool $output = true)
    {
        foreach ($this->tests as $name => $test) {
            // clear memory before start             gc_collect_cycles();

            $start    = microtime(true);
            $startMem = $maxMemory = memory_get_usage(true);

            for ($i = 0; $i < $iterations$i++) {
                $result    = $test();
                $maxMemory = max($maxMemorymemory_get_usage(true));

                unset($result);
            }

            
$dompdf->setOptions($options);
        $dompdf->setPaper($document->getPageSize()$document->getPageOrientation());
        $dompdf->loadHtml($document->getHtml());

        /* * Dompdf creates and destroys a lot of objects. The garbage collector slows the process down by ~50% for * PHP <7.3 and still some ms for 7.4 */
        $gcEnabledAtStart = gc_enabled();
        if ($gcEnabledAtStart) {
            gc_collect_cycles();
            gc_disable();
        }

        $dompdf->render();

        $this->injectPageCount($dompdf);

        if ($gcEnabledAtStart) {
            gc_enable();
        }

        


use Drupal\Core\Update\UpdateKernel;
use Symfony\Component\HttpFoundation\Request;

$autoloader = require_once 'autoload.php';

// Disable garbage collection during test runs. Under certain circumstances the // update path will create so many objects that garbage collection causes // segmentation faults. if (drupal_valid_test_ua()) {
  gc_collect_cycles();
  gc_disable();
}

$kernel = new UpdateKernel('prod', $autoloader, FALSE);
$request = Request::createFromGlobals();

$response = $kernel->handle($request);
$response->send();

$kernel->terminate($request$response);
Home | Imprint | This part of the site doesn't use cookies.