Jump to content

Build Theme!
  •  
  • Infected?

WE'RE SURE THAT YOU'LL LOVE US!

Hey there! :wub: Looks like you're enjoying the discussion, but you're not signed up for an account. When you create an account, we remember exactly what you've read, so you always come right back where you left off. You also get notifications, here and via email, whenever new posts are made. You can like posts to share the love. :D Join 93085 other members! Anybody can ask, anybody can answer. Consistently helpful members may be invited to become staff. Here's how it works. Virus cleanup? Start here -> Malware Removal Forum.

Try What the Tech -- It's free!


Photo

Apache server uptime via PHP on Windows


  • Please log in to reply
3 replies to this topic

#1 Ztruker

Ztruker

    WTT Technical Elder

  • Tech Team
  • 8,292 posts
  • Interests:Helping people fix MS Windows related computer problems of all kinds.

    Waking each morning to see the green side of the Earth!

Posted 06 November 2011 - 05:25 PM

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


Rich
 

Die with memories, not dreams. – Unknown

    Advertisements

Register to Remove


#2 terry1966

terry1966

    SuperMember

  • Visiting Tech
  • PipPipPipPipPip
  • 2,988 posts

Posted 06 November 2011 - 08:33 PM

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..../php/uptime.php

<?php
$server = $_POST['server'];

// only digits
$pattern = '/[^0-9]/';
?>
<html>
<head>
<title>Uptime</title>
</head>

<body>

<?php
$uptime = `c:\windows\system32\uptime2.bat $server`;
$uptime = explode(": ", $uptime);
$uptime = explode(", ", $uptime[1]);

$uptime_days = preg_replace($pattern, '', $uptime[0]);
$uptime_hours = preg_replace($pattern, '', $uptime[1]);
$uptime_minutes = preg_replace($pattern, '', $uptime[2]);
$uptime_seconds = preg_replace($pattern, '', $uptime[3]);



echo '<b>Uptime:</b><br><br>';

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

</body>
</html>

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.addictive...ndows-7-uptime/
this shows the uptime output near the bottom.

:popcorn:

#3 Ztruker

Ztruker

    WTT Technical Elder

  • Tech Team
  • 8,292 posts
  • Interests:Helping people fix MS Windows related computer problems of all kinds.

    Waking each morning to see the green side of the Earth!

Posted 07 November 2011 - 10:26 AM

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.

Edited by Ztruker, 07 November 2011 - 10:55 AM.

Rich
 

Die with memories, not dreams. – Unknown


#4 terry1966

terry1966

    SuperMember

  • Visiting Tech
  • PipPipPipPipPip
  • 2,988 posts

Posted 07 November 2011 - 04:30 PM

glad it was of some help, even if just to confirm what your using now is accurate. :thumbup: :popcorn:

Related Topics



0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users