Posted By

Znupi on 08/20/09


Tagged

server uptime


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

umang_nine


Server Uptime


 / Published in: PHP
 

URL: http://it-ride.blogspot.com/2009/08/php-server-uptime.html

This only works on Linux and probably other Unix-like OSes that store the uptime in /proc/uptime

  1. function get_uptime() {
  2. $file = @fopen('/proc/uptime', 'r');
  3. if (!$file) return false;
  4. $data = @fread($file, 128);
  5. if ($data === false) return false;
  6. $upsecs = (int)substr($data, 0, strpos($data, ' '));
  7. $uptime = Array (
  8. 'days' => floor($data/60/60/24),
  9. 'hours' => $data/60/60%24,
  10. 'minutes' => $data/60%60,
  11. 'seconds' => $data%60
  12. );
  13. return $uptime;
  14. }

Report this snippet  

You need to login to post a comment.