2010-05-17, 04:27 PM
Why does mybb use this to get the load:
Why not use sys_getloadavg? It works on lots more hosts than what this mess of code uses.
/**
* Returns the serverload of the system.
*
* @return int The serverload of the system.
*/
function get_server_load()
{
global $lang;
$serverload = array();
// DIRECTORY_SEPARATOR checks if running windows
if(DIRECTORY_SEPARATOR != '\\')
{
if(@file_exists("/proc/loadavg") && $load = @file_get_contents("/proc/loadavg"))
{
$serverload = explode(" ", $load);
$serverload[0] = round($serverload[0], 4);
}
if(!is_numeric($serverload[0]))
{
if(@ini_get('safe_mode') == 'On')
{
return $lang->unknown;
}
// Suhosin likes to throw a warning if exec is disabled then die - weird
if($func_blacklist = @ini_get('suhosin.executor.func.blacklist'))
{
if(strpos(",".$func_blacklist.",", 'exec') !== false)
{
return $lang->unknown;
}
}
// PHP disabled functions?
if($func_blacklist = @ini_get('disable_functions'))
{
if(strpos(",".$func_blacklist.",", 'exec') !== false)
{
return $lang->unknown;
}
}
$load = @exec("uptime");
$load = explode("load average: ", $load);
$serverload = explode(",", $load[1]);
if(!is_array($serverload))
{
return $lang->unknown;
}
}
}
else
{
return $lang->unknown;
}
$returnload = trim($serverload[0]);
return $returnload;
}
Why not use sys_getloadavg? It works on lots more hosts than what this mess of code uses.