jordanwb Posted October 3, 2008 Share Posted October 3, 2008 I know you could do this: $uptime = shell_exec('uptime'); But it gives me a really long string and I have to a bunch of formatting. Is it possible - and if so how - to get how long a Unix-based Server has been up in seconds? Link to comment https://forums.phpfreaks.com/topic/126950-getting-uptime-in-seconds/ Share on other sites More sharing options...
kenrbnsn Posted October 3, 2008 Share Posted October 3, 2008 So do a bunch of parsing: <?php $uptime = shell_exec('uptime'); $up_exp = array_map('trim',explode(',',$uptime)); list(,,$days) = explode(' ',$up_exp[0]); list($h,$m) = explode(':',$up_exp[1]); $days_sec = ($days * 86400) + ($h * 3600) + ($m * 60); echo $days_sec; ?> Ken Link to comment https://forums.phpfreaks.com/topic/126950-getting-uptime-in-seconds/#findComment-656708 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.