This is a read-only archive. No new posts or registrations. Privacy Page
Software

Apache server uptime via PHP on Windows

2 min read

This thread's last reply is from . Advice, software, and links below may be out of date — treat specific steps and download links with caution.

Looking for the outcome? Ask AI

Anyone have a neat PHP script for determining how long their Apache 2 server running under Windows (7 in my case) has been up? I've come up with this which seems to work but was wondering if any9one else had anything better?

function Uptime()
{
$httpdfile = 'D:\Apache2.2\logs\httpd.pid';

function ifif ($value, $true, $false)
{
if ($value < 2)
return $false;
else
return $true;
}

$upsince = filemtime($httpdfile);
$gettime = (time() - filemtime($httpdfile));
$days = floor($gettime / (24 * 3600));
$gettime = $gettime - ($days * (24 * 3600));
$hours = floor($gettime / (3600));
$gettime = $gettime - ($hours * (3600));
$minutes = floor($gettime / (60));
$gettime = $gettime - ($minutes * 60);
$seconds = $gettime;

$days = ifif($days , $days . ' days', $days . ' day');

$hours = ifif($hours , $hours . ' hours', $hours . ' hour');
$minutes = ifif($minutes , $minutes . ' minutes', $minutes . ' minute');
$seconds = ifif($seconds , $seconds . ' seconds', $seconds . ' second');
$ut[0] = 'Up since: ' . date('l, F jS Y, h:i a', $upsince);
$ut[1] = "Server uptime: $days $hours $minutes $seconds";
return $ut;
}

As you can see it's based off the date and time the Apache httpd.pid file was last written, which as far as I can tell, is written each time the Apache service is started. Output looks like this:

Up since: Wednesday, October 12th 2011, 08:08 pm
Server uptime: 24 days 23 hours 15 minutes 19 seconds

better? no i wouldn't think so.. but i did run across a post that uses ms uptime.exe.

http://support.microsoft.com/kb/232243

it's the 2nd post here and he's running it on win server 03 :- http://www.4webhelp.net/scripts/php/uptime.php



Uptime




Uptime:

'; echo 'Days: '.$uptime_days.'
'; echo 'Hours: '.$uptime_hours.'
'; echo 'Minutes: '.$uptime_minutes.'
'; echo 'Seconds: '.$uptime_seconds.'
'; ?>

best i could come up with from a google search, no experience with php or apache myself, so no scripts from me. :D

check win7 uptime :- http://www.addictivetips.com/windows-tips/…ndows-7-uptime/
this shows the uptime output near the bottom.

:popcorn:
Thanks Terry. I saw that one too but it's not as clean as what I already have and requires one more external program. I'll take a look to see what uptime.exe provides though.

Edit: Actually a nice program. Output looks like this:

\\XXXXXXXX has been up for: 0 day(s), 2 hour(s), 23 minute(s), 56 second(s)

Numbers match output of my PHP script so I'm very confident what I'm using is valid. Good to have a backup though,

One nice addition is that I can use uptime to query a networked computer.

Ask AI

AI can make mistakes. Check the cited posts. Archived advice can be out-of-date

Don't include personal information. Questions and selected public posts go to OpenAI. About Ask AI