Friday, October 10, 2025
HomeLanguagesPHP getrusage() Function

PHP getrusage() Function

The getrusage() function is an inbuilt function in PHP that returns current resource usage. 

Syntax:

getrusage(int $mode = 0)

Parameters:
This function has only one parameter:

  • $mode: This parameter will be called with RUSAGE_CHILDREN, if the mode will be 1.

Return Value: This function returns an associative array that is called from the system call. All entries can be accessed by using their documented fields. If failed return false.

Example 1: In the below example, will use getrusage() function and print swaps.

PHP




<?php
  
$dat = getrusage();
  
// Number of swaps
echo $dat["ru_nswap"];
?>


Output:

0

Example 2: In the below example, we will print the number of fault pages using getrusage() function.

PHP




<?php
$dat = getrusage();
  
// User time used (seconds)
echo $dat["ru_utime.tv_sec"];
  
// User time used (microseconds)
echo $dat["ru_utime.tv_usec"]; 
?>


Output:

08624

Note: Output can be different according to the system.

Reference: https://www.php.net/manual/en/function.getrusage.php

RELATED ARTICLES

Most Popular

Dominic
32350 POSTS0 COMMENTS
Milvus
87 POSTS0 COMMENTS
Nango Kala
6718 POSTS0 COMMENTS
Nicole Veronica
11880 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11941 POSTS0 COMMENTS
Shaida Kate Naidoo
6838 POSTS0 COMMENTS
Ted Musemwa
7101 POSTS0 COMMENTS
Thapelo Manthata
6794 POSTS0 COMMENTS
Umr Jansen
6794 POSTS0 COMMENTS