PHP 8.3 新特性 - gc_status() 返回额外的垃圾回收信息
hi,我是温新,一名 PHPer
PHP 的 gc_status() 函数返回有关 PHP 垃圾回收器的统计信息,例如是否正在运行垃圾回收器、是否受到保护以及缓冲区大小。当调试长时间运行的 PHP 应用程序以检测和优化内存使用情况时,这些信息非常有用。
<?php
    
print_r(gc_status());
输出信息如下
Array
(
    [running] => 
    [protected] => 
    [full] => 
    [runs] => 0
    [collected] => 0
    [threshold] => 10001
    [buffer_size] => 16384
    [roots] => 0
    [application_time] => 0.006616683
    [collector_time] => 0
    [destructor_time] => 0
    [free_time] => 0
)
PHP 8.3 之前,gc_status() 函数返回一个包含四个键的数组:
| 键 | 类型 | 描述 | 
|---|---|---|
runs | 
Integer | 垃圾回收器运行的次数 | 
collected | 
Integer | 收集的对象数 | 
threshold | 
Integer | 缓冲区中将触发垃圾回收的根的数量 | 
roots | 
Integer | 缓冲区中的当前根数 | 
在 PHP 8.3 中,gc_status 函数返回八个额外的字段:
| 键 | 类型 | Description | 
|---|---|---|
running | 
Boolean | 如果垃圾收集器正在运行,则返回 true,否则为 false | 
protected | 
Boolean | 如果垃圾收集器受到保护并且禁止添加根目录,则返回 true,否则为 false | 
full | 
Boolean | 如果垃圾收集器缓冲区大小超过 GC_MAX_BUF_SIZE,则返回 true。当前设置为 0x40000000(= 1024³) | 
buffer_size | 
Integer | 当前垃圾收集器缓冲区大小 | 
application_time | 
Float | 应用程序的总时间,以秒为单位(包括 collector_time)。 | 
collector_time | 
Float | 收集周期所花费的时间,以秒为单位(包括 destructor_time 和 free_time)。 | 
destructor_time | 
Float | 在循环收集期间执行析构函数所花费的时间,以秒为单位。 | 
free_time | 
Float | 在循环收集期间释放值所花费的时间,以秒为单位。 | 
请登录后再评论