i had a few people ask me how can they get the uptime on windows to display it on a webpage like i do on my site on linux.
after doing some research i found its almost impossible unless you:
1) get some exe file from microsoft and execute it to get the uptime.
2) use the operating system pagefile that resets the time everytime the os is rebooted.
so after i found the location of the pagefile i came up with this script:
<?php
$pagefile = 'c:\pagefile.sys'; // Path to system pagefile. Default is c:\\pagefile.sys
function ifif ($value, $true, $false)
{
if ($value == 0)
{
return $false;
}
else
{
return $true;
}
}
$upsince = filemtime($pagefile);
$gettime = (time() - filemtime($pagefile));
$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 != 1, $days . ' days', $hours . ' day');
$hours = ifif($hours != 1, $hours . ' hours', $hours . ' hour');
$minutes = ifif($minutes != 1, $minutes . ' minutes', $minutes . ' minute');
$seconds = ifif($seconds != 1, $seconds . ' seconds', $seconds . ' second');
echo 'Server uptime: ' . $days . ' ' . $hours . ' ' . $minutes . ' ' . $seconds;
echo '<br /> Up since: ' . date('l. F jS, Y. h:i a', $upsince);
?>
its only been tested on windows 2000, and windows xp. It works on php 4.x.x, although i don't see why it shouldn't work on php 3.x
if you run a windows webserver, win95,98 i would like to know if it works on it. the system pagefile could possible be located elsewhere on these operating systems.
pagefile.sys is an invisible file, so you would have to search for it using the operating system search tool.
just change c:\ to the letter of your operating system.