(PHP 7 >= 7.3.0, PHP 8)
gc_status — Obtiene información sobre el recolector de basura
Obtiene información sobre el estado actual del recolector de basura.
Esta función no contiene ningún parámetro.
Devuelve un array asociativo con los siguientes elementos:
"runs"
"collected"
"threshold"
"roots"
"running"
"protected"
"full"
"buffer_size"
"application_time"
"collector_time"
"destructor_time"
"free_time"
| Versión | Descripción |
|---|---|
| 8.3.0 |
gc_status() devuelve ahora los campos adicionales siguientes:
"running", "protected",
"full", "buffer_size",
"application_time", "collector_time",
"destructor_time", y "free_time".
|
Ejemplo #1 Uso de gc_status()
<?php
// crear el árbol de objetos que requiere la recolección de basura
$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());Resultado del ejemplo anterior es similar a:
array(4) {
["runs"]=>
int(5)
["collected"]=>
int(100002)
["threshold"]=>
int(50001)
["roots"]=>
int(0)
}
Resultado del ejemplo anterior en PHP 8.3 es similar a:
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)
}