| px | top | add code | search | signup | login | help |
<?
#============================================================
# Returns the uptime of a Linux system by parsing through /proc/uptime.
# It returns a 4-field array (days, hours, minutes, seconds).
# I typically use it like:
# $ut = linuxUptime();
# echo "Time since last reboot: $ut[0] days, $ut[1] hours, $ut[2] minutes";
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 );
}
?>
Comments or questions?
PX is running PHP 5.2.11
Thanks to Miranda Productions for hosting and bandwidth.
Use of any code from PX is at your own risk.