Sep 19, 2008

PHP:: FreeBSD uptime status

Since FreeBSD does not have /proc/uptime, there is an equivalent with sysctl. You need to execute an unix command with php, and the third word in the string holds the UNIX timestamp of kernel boot. This function works great with duration() mentioned below.
function uptime() {
 preg_match('#up (.*?) \d+ user#is',exec('uptime'),$a);
 $a = str_replace(',','',$a[1]);
 $a = preg_replace(array('#\:#','#$#'),array(' hours ',' minutes'),$a);
 strtotime("-$a")
 
 $sup = duration($a);
 
 $uptime = "Uptime: $sup";
 
 return $uptime;
}

1 comment:

Tagnard said...

Thanks a bunch. I was looking for this ^_^