PDA

View Full Version : Here is how to get your server's load


Dylan Leblanc
04-23-2003, 10:18 PM
I copied this code from vBulletin's admin control panel.

<?

if ($stats = @exec("uptime")) {
preg_match("/averages?: ([0-9\.]+),[\s]+([0-9\.]+),[\s]+([0-9\.]+)/", $stats, $regs);
?>Server load averages: <?=$regs[1]?>, <?=$regs[2]?>, <?=$regs[3]?><?
}

?>

Dylan Leblanc
04-27-2003, 12:19 PM
... and as a nice little function:

Server load averages: <?=implode(', ', ServerLoad())?><br>

<?

function ServerLoad()
{

if ($stats = @exec("uptime")) {
preg_match("/averages?: ([0-9\.]+),[\s]+([0-9\.]+),[\s]+([0-9\.]+)/", $stats, $regs);
return array($regs[1], $regs[2], $regs[3]);
}

}

?>

weronpc
05-04-2003, 03:11 AM
Hello,

can you explain a little how this script work? I don't understand, what is exec("uptime"), is uptime a file name???

thanx:)

Dylan Leblanc
05-05-2003, 03:38 AM
uptime is a command on linux machines that gives the amount of time since it has started up, and gives the server loads. This is an example output of the uptime command:
7:39pm up 23 days, 4:54, 1 user, load average: 3.79, 3.75, 3.16

exec() is a PHP function to execute shell commands and return the output back to PHP.