Patty Posted December 1, 2007 Share Posted December 1, 2007 I don't know if there's a windows server uptime working on the new version (I didn't have the time to upgrade it yet ), but I've found a script that is working just fine on my server. It can be found here: http://www.xenocafe.com/tutorials/php/realtime_server_uptime_in_windows/index.php Here's the script: <?php // format the uptime in case the browser doesn't support dhtml/javascript // static uptime string function format_uptime($seconds) { $secs = intval($seconds % 60); $mins = intval($seconds / 60 % 60); $hours = intval($seconds / 3600 % 24); $days = intval($seconds / 86400); if ($days > 0) { $uptimeString .= $days; $uptimeString .= (($days == 1) ? " day" : " days"); } if ($hours > 0) { $uptimeString .= (($days > 0) ? ", " : "") . $hours; $uptimeString .= (($hours == 1) ? " hour" : " hours"); } if ($mins > 0) { $uptimeString .= (($days > 0 || $hours > 0) ? ", " : "") . $mins; $uptimeString .= (($mins == 1) ? " minute" : " minutes"); } if ($secs > 0) { $uptimeString .= (($days > 0 || $hours > 0 || $mins > 0) ? ", " : "") . $secs; $uptimeString .= (($secs == 1) ? " second" : " seconds"); } return $uptimeString; } // get the server statistics with "net statistics server" by shell_exec $winstats = shell_exec("net statistics server"); // grab the date & time the server started up preg_match("(\d{1,2}/\d{1,2}/\d{4}\s+\d{1,2}\:\d{2}\s+\w{2})", $winstats, $matches); // convert the readable date & time to a timestamp and deduct it from the current timestamp // thus giving us the total uptime in seconds $uptimeSecs = time() - strtotime($matches[0]); // get the static uptime $staticUptime = "Server Uptime: ".format_uptime($uptimeSecs); ?> <html> <head> <script language="javascript"> <!-- var upSeconds=<?php echo $uptimeSecs; ?>; function doUptime() { var uptimeString = "Server Uptime: "; var secs = parseInt(upSeconds % 60); var mins = parseInt(upSeconds / 60 % 60); var hours = parseInt(upSeconds / 3600 % 24); var days = parseInt(upSeconds / 86400); if (days > 0) { uptimeString += days; uptimeString += ((days == 1) ? " day" : " days"); } if (hours > 0) { uptimeString += ((days > 0) ? ", " : "") + hours; uptimeString += ((hours == 1) ? " hour" : " hours"); } if (mins > 0) { uptimeString += ((days > 0 || hours > 0) ? ", " : "") + mins; uptimeString += ((mins == 1) ? " minute" : " minutes"); } if (secs > 0) { uptimeString += ((days > 0 || hours > 0 || mins > 0) ? ", " : "") + secs; uptimeString += ((secs == 1) ? " second" : " seconds"); } var span_el = document.getElementById("uptime"); var replaceWith = document.createTextNode(uptimeString); span_el.replaceChild(replaceWith, span_el.childNodes[0]); upSeconds++; setTimeout("doUptime()",1000); } // --> </script> </head> <body onLoad="doUptime();"> <!-- Uses the DIV tag, but SPAN can be used as well --> <div id="uptime" style="font-weight:bold;"><?php echo $staticUptime; ?></div> </body> </html> Save it as uptime.php or something like that, upload it to your server's web directory and that's it! Call it on your browser and you'll see the uptime up to the running seconds. Enjoy! 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.