[php] Uptime in FreeBSD

sean.ferguson

OSNN Veteran Addict
Joined
4 Jul 2003
Messages
1,693
im using freebsd4.10-RELEASE running Apache 2 and PHP5.
I want something so i can see the server's uptime in a php file. (eg ~/uptime.php)
 
got it:

Code:
<?
function uptime() {
	$s = explode( " ", exec("/sbin/sysctl -n kern.boottime") );
	$a = str_replace( ",", "", $s[3]);
	$sys_ticks = time() - $a;

	$min   = $sys_ticks / 60;
	$hours = $min / 60;
	$days  = floor( $hours / 24 );
	$hours = floor( $hours - ($days * 24) );
	$min   = floor( $min - ($days * 60 * 24) - ($hours * 60) );

	if( $days ) {
		$result = "$days day";
		if( $days != 1 ) $result .= "s";
		$result .= " ";
	}

	if( $hours ) {
		$result .= "$hours hour";
		if( $hours != 1 ) $result .= "s";
		$result .= " ";
	}

	$result .= "$min minute";
	if( $min != 1 ) $result .= "s";

	return $result;
}

echo uptime();
?>
 
On my Windows server I used this:
Code:
$uptime = exec("uptime.exe");
//breaking at 'for:'
$uptime = explode("for:", $uptime);
//only using the last bit, since I am not interested in the stuff before 'for:'
$uptime = $uptime[1];
The uptime.exe utility used a format like
Code:
\\<computername> has been running for: d day(s), h hour(s) and m minute(s)
The easiest way would be using an uptime util that uses the Unix timestamp format, so you can format the time and date yourself. I am still looking for one for myself, so keep me posted :) (also for freebsd 4.10)
 

Members online

No members online now.

Latest profile posts

Also Hi EP and people. I found this place again while looking through a oooollllllldddd backup. I have filled over 10TB and was looking at my collection of antiques. Any bids on the 500Mhz Win 95 fix?
Any of the SP crew still out there?
Xie wrote on Electronic Punk's profile.
Impressed you have kept this alive this long EP! So many sites have come and gone. :(

Just did some crude math and I apparently joined almost 18yrs ago, how is that possible???
hello peeps... is been some time since i last came here.
Electronic Punk wrote on Sazar's profile.
Rest in peace my friend, been trying to find you and finally did in the worst way imaginable.

Forum statistics

Threads
62,015
Messages
673,494
Members
5,621
Latest member
naeemsafi
Back