PHP sys_getloadavg() Function
The PHP sys_getloadavg() function is used to get system load average. It returns three samples representing the average system load (the number of processes in the system run queue) over the last 1, 5 and 15 minutes, respectively. It returns false on failure.
Syntax
sys_getloadavg()
Parameters
No parameter is required.
Return Value
Returns an array with three samples (last 1, 5 and 15 minutes).
Example: sys_getloadavg() example
The example below shows the usage of sys_getloadavg() function.
<?php $load = sys_getloadavg(); //displaying the system load average print_r($load); //taking action when the load average in //last 1 minute is greater than 0.8 if ($load[0] > 0.80) { header('HTTP/1.1 503 Too busy, try again later'); die('Server too busy. Please try again later.'); } ?>
The output of the above code will be similar to:
Array ( [0] => 0.01 [1] => 0.04 [2] => 0.01 )
❮ PHP Miscellaneous Reference