gc_status()
gc_status() — Gets information about the garbage collector.
Built-in function of PHP 8.5. The manual lists it as available in PHP 7 >= 7.3.0, PHP 8. This page is the reference card: signature, parameters and return value, plus the changelog and the example the manual provides.
What it does
Gets information about the current state of the garbage collector.
Signature
gc_status(): array
Parameters
This function takes no parameters.
Return value
Returns an associative array with the following elements: "runs" "collected" "threshold" "roots" "running" "protected" "full" "buffer_size" "application_time" "collector_time" "destructor_time" "free_time" "runs" "collected" "threshold" "roots" "running" "protected" "full" "buffer_size" "application_time" "collector_time" "destructor_time" "free_time"
Example
A runnable snippet:
// 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());
Output:
array(4) { ["runs"]=> int(5) ["collected"]=> int(100002) ["threshold"]=> int(50001) ["roots"]=> int(0) }
Changelog
| Version | Change |
|---|---|
| 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". |
All PHP 8.5 built-in functions
Reference card built from the PHP manual page gc_status() (PHP documentation, CC BY 3.0). The page is generated from the manual, so the wording of the parameter and return value text follows php.net.