gc_status

(PHP 7 >= 7.3.0, PHP 8)

gc_status — 가비지 수집기에 대한 정보를 가져옵니다.


설명

gc_status(): array

가비지 수집기의 현재 상태에 대한 정보를 가져옵니다.


매개변수

이 함수에는 매개변수가 없습니다.


반환 값

다음 요소가 포함된 연관 배열을 반환합니다.

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

Examples

예제 #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)
}
                

기타