array ( 0 => 'index.php', 1 => 'PHP Manual', ), 'head' => array ( 0 => 'UTF-8', 1 => 'uk', ), 'this' => array ( 0 => 'function.gc-status.php', 1 => 'gc_status', 2 => 'Gets information about the garbage collector', ), 'up' => array ( 0 => 'ref.info.php', 1 => 'Функції налаштування та отримання інформації про PHP', ), 'prev' => array ( 0 => 'function.gc-mem-caches.php', 1 => 'gc_mem_caches', ), 'next' => array ( 0 => 'function.get-cfg-var.php', 1 => 'get_cfg_var', ), 'alternatives' => array ( ), 'source' => array ( 'lang' => 'en', 'path' => 'reference/info/functions/gc-status.xml', ), 'history' => array ( ), ); $setup["toc"] = $TOC; $setup["toc_deprecated"] = $TOC_DEPRECATED; $setup["parents"] = $PARENTS; manual_setup($setup); contributors($setup); ?>

gc_status

(PHP 7 >= 7.3.0, PHP 8)

gc_statusGets information about the garbage collector

Опис

gc_status(): array

Gets information about the current state of the garbage collector.

Параметри

У цієї функції немає параметрів.

Значення, що повертаються

Returns an associative array with the following elements:

Журнал змін

Версія Опис
8.3.0 gc_status() now returns the following additional fields: "running", "protected", "full", "buffer_size", "application_time", "collector_time", "destructor_time", and "free_time".

Приклади

Приклад #1 gc_status() Usage

<?php

// create object tree that needs gc collection
$a = new stdClass();
$a->b = [];
for (
$i = 0; $i < 100000; $i++) {
$b = new stdClass();
$b->a = $a;
$a->b[] = $b;
}
unset(
$a);
unset(
$b);
gc_collect_cycles();

var_dump(gc_status());

Поданий вище приклад виведе щось схоже на:

array(4) {
  ["runs"]=>
  int(5)
  ["collected"]=>
  int(100002)
  ["threshold"]=>
  int(50001)
  ["roots"]=>
  int(0)
}

В PHP 8.3 поданий вище приклад виведе щось схоже на:

array(12) {
  ["running"]=>
  bool(false)
  ["protected"]=>
  bool(false)
  ["full"]=>
  bool(false)
  ["runs"]=>
  int(5)
  ["collected"]=>
  int(100002)
  ["threshold"]=>
  int(50001)
  ["buffer_size"]=>
  int(131072)
  ["roots"]=>
  int(0)
  ["application_time"]=>
  float(0.031182458)
  ["collector_time"]=>
  float(0.020106291)
  ["destructor_time"]=>
  float(0)
  ["free_time"]=>
  float(0.003707167)
}

Прогляньте також