大网数据广告活动
PHP 语言与运行手册

gc_status · 获取有关垃圾回收的信息

· 52CE 我爱测

版本 说明 8.3.0 gc_status() 现在会返回以下附加字段: "running"、"protected"、 "full"、"buffer_size"、 "application_time"、"collector_time"、 "destructor_time" 和 "free_time"。

gc_status

(PHP 7 >= 7.3.0, PHP 8)

gc_status — 获取有关垃圾回收的信息

说明

function gc_status(): array

获取有关当前垃圾收集状态的信息。

参数

此函数没有参数。

返回值

返回包含以下元素的关联数组:

  • "runs"

  • "collected"

  • "threshold"

  • "roots"

  • "running"

  • "protected"

  • "full"

  • "buffer_size"

  • "application_time"

  • "collector_time"

  • "destructor_time"

  • "free_time"

更新日志

版本 说明
8.3.0 gc_status() 现在会返回以下附加字段: "running"、"protected"、 "full"、"buffer_size"、 "application_time"、"collector_time"、 "destructor_time" 和 "free_time"。

示例

示例 #1 gc_status() 用法

<?php

// 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());

以上示例的输出类似于:

array(4) {
  ["runs"]=>
  int(5)
  ["collected"]=>
  int(100002)
  ["threshold"]=>
  int(50001)
  ["roots"]=>
  int(0)
}

上述示例在 PHP 8.3 中的输出类似于:

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)
}

参见

来源:PHP Documentation Group · 作者与贡献记录 · CC BY 3.0。离线整理了版式、链接和媒体显示。

资料来源与适用范围

资料来源
PHP Documentation Group
适用范围
请按文中版本与环境说明核对
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。