Skip to content

Commit

Permalink
Update uptime.php
Browse files Browse the repository at this point in the history
  • Loading branch information
vladc committed Mar 5, 2013
1 parent 0a6f110 commit 0be0c62
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions uptime.php
@@ -1,9 +1,19 @@
<?php
function sec2human($time) {
$seconds = $time%60;
$mins = floor($time/60)%60;
$hours = floor($time/60/60)%24;
$days = floor($time/60/60/24);
return $days > 0 ? $days . ' day'.($days > 1 ? 's' : '') : $hours.':'.$mins.':'.$seconds;
}

$array = array();
$data = shell_exec('uptime');
$uptime = explode(' up ', $data);
$uptime = explode(',', $uptime[1]);
$array['uptime'] = $uptime[0];
$fh = fopen('/proc/uptime', 'r');
$uptime = fgets($fh);
fclose($fh);
$uptime = explode('.', $uptime, 2);
$array['uptime'] = sec2human($uptime[0]);


$fh = fopen('/proc/meminfo', 'r');
$mem = 0;
Expand Down Expand Up @@ -55,4 +65,4 @@
<div class="bar bar-success" style="width: 100%;"><small>Up</small></div>
</div>';

echo json_encode($array);
echo json_encode($array);

0 comments on commit 0be0c62

Please sign in to comment.