Linux uptime
By: Daniel
If you want to show the uptime of your linux server on your website, you can do so very easily.
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(); // If you would like to show the seconds as well just add [ , $ut[3] seconds ] after minutes. echo "Time since last reboot: $ut[0] days, $ut[1] hours, $ut[2] minutes";
Just call the $ut = linuxUptime() function and then you can use the variables to show the time.
**NOTE: Your server must allow you to run the exec() php command. Some hosts disable the execution of this and several other php functions.





















February 24th, 2007 at 11:37 am
How can i get this script to connect to many servers, and find and echo all the uptimes for all the servers ??
February 25th, 2007 at 10:09 pm
[...] This code loops through the $sites array to determine which sites to gather information from. On every server you wish to check the uptime, create a file in the root of the domain called: linuxUptime.php. In this file you should include the code found in the Linux Uptime tutorial and only echo out the uptime. Anything that is output in the linuxUptime.php file will show up in the above output. [...]
February 25th, 2007 at 10:11 pm
Here is a tutorial to gather uptime from multiple servers.
http://www.wlscripting.com/tutorial/42
January 20th, 2008 at 12:52 am
how to make to show the max uptime of the server and from when the server runing?