PHP 8.3: gc_status()
returns additional GC information
PHP's gc_status()
function returns statistics of PHP Garbage Collector, such as whether GC is running, whether GC is protected, and the buffer size. This information can be useful when debugging long-running PHP applications to detect and optimize memory usage.
var_dump(gc_status());
Currently, gc_status
function returns an array with four keys:
Field | Type | Description |
---|---|---|
runs |
Integer | Number of times the garbage collector has run. |
collected |
Integer | The number of objects collected. |
threshold |
Integer | The number of roots in the buffer which will trigger garbage collection. |
roots |
Integer | The current number of roots in the buffer. |
In PHP 8.3, the gc_status
function returns eight additional fields:
Field | Type | Description |
---|---|---|
running |
Boolean | true if the garbage collector is running. false otherwise. |
protected |
Boolean | true if the garbage collector is protected and root additions are forbidden. false otherwise. |
full |
Boolean | true if the garbage collector buffer size exceeds GC_MAX_BUF_SIZE . This is currently set to 0x40000000 (= 1024³.) |
buffer_size |
Integer | Current garbage collector buffer size. |
application_time |
Float | Total application time, in seconds (including collector_time ). |
collector_time |
Float | Time spent collecting cycles, in seconds (including destructor_time and free_time ). |
destructor_time |
Float | Time spent executing destructors during cycle collection, in seconds. |
free_time |
Float | Time spent freeing values during cycle collection, in seconds. |
Backwards Compatibility Impact
In PHP 8.3, the gc_status
function returns additional fields in its return array. There are no function signature changes or return value type changes apart from the inclusion of the eight new fields.
Given that this function returns PHP's internal GC data, the additional information returned cannot be retrieved with user-land PHP functions. This makes it not possible to port this change to older PHP versions.