Design - Server Uptime
Code to monitor server uptime.
The following code will display the time elapsed since the last server reboot.
<?
function linuxUptime() {
$ut = strtok( exec( "cat /proc/uptime" ), "." );
$days = sprintf( "%2d", ($ut/(3600*24)) );
$hours = sprintf( "%2d", ( ($ut % (3600*24)) / 3600) );
$min = sprintf( "%2d", ($ut % (3600*24) % 3600)/60 );
$sec = sprintf( "%2d", ($ut % (3600*24) % 3600)%60 );
return array( $days, $hours, $min, $sec );
}
$ut = linuxUptime();
// If you would like to show the seconds as well just add [ , $ut[3] seconds ] after minutes.
echo "Time since last reboot: $ut[0] days, $ut[1] hours, $ut[2] minutes";
?>
Cut and paste the code into a php file named (something like) uptime.php and then save it to the root directory of your website. Then when you visit the page (http://www.yoursite.com/uptime.php) it will show the time elapsed since the last server reboot.
|