getrusage
At an operating system level it’s easy to see the number of page faults, swaps, flushes etc for your computer, but how do you accomplish it through PHP? The getrusage function can be used to return an associative array containg details of system level calls. Its signature looks like this:
array getrusage ( [int who])
This function only works on Linux. Here’s some sample code:
<?php
$usage_stats = getrusage();
// Print the entire contents of the $usage_stats array
print_r($usage_stats);
// Show some individual parts of the $usage_stats array
echo “Number of page faults: ” . $usage_stats[”ru_majflt”];
echo “User time used in seconds: ” . $usage_stats[”ru_utime.tv_sec”];
?>
