Domain Discussion Board

Go Back   Domain Discussion Board > Web Hosting & Web Design > Scripts

 
Reply
 
LinkBack Thread Tools Display Modes
Server Uptime Script
Old
  (#1 (permalink))
Evans
Junior Member
Evans is on a distinguished road
 
Status: Offline
Posts: 31
Points: 1,112.8
Bank: 0.0
Total Points: 1,112.8
Donate
Join Date: Jun 2006
Rep Power: 0
Server Uptime Script - 06-03-2006, 01:04 PM

This script is simple and tells you the exact time that yourserver has been up it is written in PHP and it is pretty simple to install just copy and paste the code below into notepad and save it with a .php extension then just put it to your server

Quote:
<?php
/************************************************** ********************
Dynamic Uptime Script (exec version) in PHP / JavaScript / DHTML

This code is free for use by anyone that finds it useful.

This is an updated version of the script that was originally
released on June 1, 2006. Thanks to tayson for pointing
out the code wasn't working on one of the lines.

I also made it so the uptime is statically written in the event
that the viewing browser doesn't do JavaScript or DHTML (like
Lynx). The old version displayed nothing because I put a non-
breaking space between the DIV tags (oops!).
************************************************** *********************/

// 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;
}

// read in the uptime (using exec)
$uptime = exec("cat /proc/uptime");
$uptime = split(" ",$uptime);
$uptimeSecs = $uptime[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>

Hopefully some of you guys here might find this useful.

Greetz, Evans
   
Reply With Quote
Re: Server Uptime Script
Old
  (#2 (permalink))
mtorregiani
mtorregiani is on a distinguished road
 
mtorregiani's Avatar
 
Status: Online
Posts: 1,792
Points: 1.7
Bank: 3,580.0
Total Points: 3,581.7
Donate
Join Date: Apr 2006
Location: Montevideo, Uruguay
Rep Power: 4
Re: Server Uptime Script - 06-03-2006, 01:17 PM

It sounds good

i'll try it
   

Reply With Quote
Sponsored Links
Re: Server Uptime Script
Old
  (#3 (permalink))
Evans
Junior Member
Evans is on a distinguished road
 
Status: Offline
Posts: 31
Points: 1,112.8
Bank: 0.0
Total Points: 1,112.8
Donate
Join Date: Jun 2006
Rep Power: 0
Re: Server Uptime Script - 06-03-2006, 01:40 PM

If you want to view an online demo please visit:
http://www.vasp.co.in/uptime.php

Greetz, Evans
   
Reply With Quote
Re: Server Uptime Script
Old
  (#4 (permalink))
Shaun
Banned
Shaun is an unknown quantity at this point
 
Status: Offline
Posts: 26
Points: 8.2
Bank: 0.0
Total Points: 8.2
Donate
Join Date: Jun 2006
Rep Power: 0
Re: Server Uptime Script - 06-04-2006, 05:48 AM

Nice! you don't even have to refresh the page. Cheers for that man.
   
Reply With Quote
Re: Server Uptime Script
Old
  (#5 (permalink))
s-Lec
Platinum Member
s-Lec is an unknown quantity at this point
 
Status: Offline
Posts: 705
Points: 59.0
Bank: 1,806.1
Total Points: 1,865.1
Donate
Join Date: Jun 2006
Location: Auckland
Rep Power: 0
Re: Server Uptime Script - 06-04-2006, 05:46 PM

Awesome job, you can also find the up time from different seb pages


██ Love ME?
██ Visit My BLOG! Luv5! <3

   
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Points Per Thread View: 0.1
Points Per Thread: 15.0
Points Per Reply: 5.0


Similar Threads
Thread Thread Starter Forum Replies Last Post
Wanted: Paid to Search script! Domain Dan Scripts 8 03-10-2007 05:51 AM
Email Script giomanach Scripts 9 11-10-2006 08:08 AM
FastPage - new AJAX script for Laziness ASP.NET developers TJmaster Scripts 2 03-06-2006 04:48 AM


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 ©2007, Crawlability, Inc.