note 62557 modified in function.sys-getloadavg by kalle
| From: | kalle@php.net | Date: | Fri, 30 Jan 2015 00:04:19 +0000 |
| Subject: | note 62557 modified in function.sys-getloadavg by kalle | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-201561@lists.php.net to get a copy of this message | ||
The code below mimics the output of sys_getloadavg(). You may have to tweak the way the substring is
captured for different distros.
<?php
function sys_getloadavg_hack()
{
$str = substr(strrchr(shell_exec("uptime"),":"),1);
$avs = array_map("trim",explode(",",$str));
return $avs;
}
print_r(sys_getloadavg_hack());
// Array
// (
// [0] => 6.24
// [1] => 4.92
// [2] => 3.99
// )
?>
This function is a neat way of running low priority or non-essential cron jobs on a busy server - if
the load is high, don't continue with the task (and try again in a few minutes time).
--was--
The code below mimics the output of sys_getloadavg(). You may have to tweak the way the substring is
captured for different distros.
<?
function sys_getloadavg_hack()
{
$str = substr(strrchr(shell_exec("uptime"),":"),1);
$avs = array_map("trim",explode(",",$str));
return $avs;
}
print_r(sys_getloadavg_hack());
// Array
// (
// [0] => 6.24
// [1] => 4.92
// [2] => 3.99
// )
?>
This function is a neat way of running low priority or non-essential cron jobs on a busy server - if
the load is high, don't continue with the task (and try again in a few minutes time).
http://php.net/manual/en/function.sys-getloadavg.php