Skip to content

Instantly share code, notes, and snippets.

@k0nsl
Created December 18, 2013 12:31
Show Gist options
  • Select an option

  • Save k0nsl/8021525 to your computer and use it in GitHub Desktop.

Select an option

Save k0nsl/8021525 to your computer and use it in GitHub Desktop.
Uptime via PHP. Saved from my blog since I have now replaced this with a much more efficient and secure method (bash > html outoput).
<?php
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);
}
$ut = linuxUptime();
echo "<small>\nUptime: $ut[0] days, $ut[1] hours and $ut[2] minutes</small>\n";
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment