PHP 8.3: gc_status() returns additional GC information

TypeNew Feature

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.


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 four 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.

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 four 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.