PHP8 gc_status — 獲取有關垃圾回收的信息

2023-09-13 15:04 更新

(PHP 7 >= 7.3.0, PHP 8)

gc_status — 獲取有關垃圾回收的信息

說明

gc_status(): array

獲取有關當前垃圾收集狀態(tài)的信息。

參數(shù)

此函數(shù)沒有參數(shù)。

返回值

返回包含以下元素的關聯(lián)數(shù)組:

  • "runs"
  • "collected"
  • "threshold"
  • "roots"

示例

示例 #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)
}

參見

  • 垃圾回收


以上內容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號