You are using a browser which is not compatible with CSS (for more information, see Tara's tutorial). Because of this, it is possible that our website may not appear correctly in your browser. We apologise for the inconvenience, and recommend you upgrade your browser to one which is compatible with CSS. For more information, please visit our Browser Upgrade page.

4WebHelp

Scripts: PHP: Server Uptime

This script will output the current server's uptime. This is subject to being on a compatible OS (probably Unix only).

<?php

###########################################################################
#                                                                         #
# Copyright © http://www.4webhelp.net/                                    #
# Neither http://www.4webhelp.net/ nor its members accept any             #
# responsibility, either expressed or implied, for any damage caused by   #
# using this script or the misuse of this script.                         #
#                                                                         #
#                                                                         #
#                          INSTRUCTIONS                                   #
#                                                                         #
# 1) Copy this code to an editor such as Notepad and save it with a       #
# .php  extension.                                                        #
# 2) FTP this file to a folder on your site in ASCII mode                 #
# 3) Call up this file in your web browser to see your server's uptime    #
#                                                                         #
###########################################################################

  $data = shell_exec('uptime');
  $uptime = explode(' up ', $data);
  $uptime = explode(',', $uptime[1]);
  $uptime = $uptime[0].', '.$uptime[1];

  echo ('Current server uptime: '.$uptime.'

'); ?> <p>This script courtesy of <a href="http://www.4webhelp.net/">4WebHelp</a>.</p>
Latest comments
Pete
I don't know php, but was looking for something that would tell me uptime. I followed the instructions, but I only get this return: Current server uptime: ,

Any idea why I'm only getting a comma?
Max
thanks guys
hehehe
here is mine for Windows Server 2003, tested and works just fine, its based on another comment here Smile

i had to download the uptime.exe from ms, just search for it on their site..


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>


uptime2.bat:
@echo off

uptime.exe %1
Jhano
this is what i need, thanx for your help, how can i display the uptime with the type of os or distro will show. thanks very much.
Peter
are there any php scripts to resolve an IP address to FQDN and visa-versa, depending which is entered in, and return to the webpage.
Fredrik
<?php Uptime: <?=`uptime;`?> did the trick, thx!
HYEdomain
i like what i sow. however what i m trying to do is make other system read the uptime. only one that it reads is localhost. i m not sure how to do that. any ideas?
Tim
Simple way:

Uptime: <?=`uptime;`?>
Mark
For FreeBSD try:


<?php

$s = explode( " ", exec("/sbin/sysctl -n kern.boottime") );
$a = str_replace( ",", "", $s[3]);
$uptime = time() - $a;    

?>
AmaruL
end u dont have a uptime for windows servers? pls
zHosting
Hi.

I have my own hosting company. What I wanna do is to provide my future members with a way to be able to have site monitoring, by providing them with a site uptime membership site through my hosting site.

I was wondering if anyone would post tutorials on how to build one, which I can provide my members the ability to do the following:

1. Members signup for a free/paid account to start monitoring their website uptime.

2. Setup multiple server monitoring stations (you will need to have servers in these areas) located in different parts of the world so that your members' websites can be monitored in not just only 1 server location.

3. Members can select the check intervals (2,5,10,15,30 or 60mins) for each monitored service 24 hours per day, 7 days per week, 365 days per year.

4. If there is a downtime detected by any of the server monitoring locations, an email and/or SMS will be sent to your members notifying them that their website is down so that they can take follow-up actions. With our SMS-ALERT module integrated into our Site Uptime, sending out SMS messages through the sms gateway is done automatically.

5. Site Uptime Enterprise also provides real-time statistics as well as a summary of your members' uptime. Visual representations such as bar charts and graphical pies are include in our software for a quick overview. Members can also opt to receive monthly reports of their websites.

Also, with the following features:

MEMBER FUNCTIONS:
   * Monitoring Features
         - Monitoring intervals - Supports time-intervals of 2,5,10,15,30 and 60mins for monitoring service.
         - Multiple monitoring service - Members can monitor more than 1 website or domain names
         - Multiple monitoring locations - Members are able to monitor from different server locations
         - Email and SMS alert - Members are notified by email and/or SMS with our SMS-Alert module integrated into Site Uptime Enterprise.
         - Site Uptime Enterprise supports the following protocols:
               + HTTP: Web Server
               + POP3: Email Server
               + SMTP: Outgoing Email Server
               + FTP: File Transfer Protocol
               + SSL: Secure Socket Layer
               + Custom ports
               + PINGS
               + DNS
   * Members Login System
         - Member registration system
         - Password forget function
         - Paypal integrated - Members can easily upgrade their account through paypal payments
         - Member account upgrade page - Option for free members to upgrade to paid account with enhance web monitoring services.
   * QuickCheck
         - Instant check the status of the hostname
         - Supports multiple server location checks
   * Member Profile
         - Ability to edit and save member's profile
         - Set custom time zones
         - Members can set multiple alert emails
         - Ability to set multiple mobile phone numbers for SMS alert
         - Members can have the option to receive monthly email uptime reports
   * Member Services
         - Ability to edit/delete existing monitoring services.
         - Members are able to enable/disable existing services.
         - Members can view last check date as well as the host name and service details.
         - View statistics for each services.
         - Add new monitoring services.
               + Set hostname and service type (http,pop3 or custom ports)
               + Select check intervals for monitoring
               + Choose locations to monitor the service
               + Set notification settings for email and SMS
   * Member Statistics
         - Built-in bar charts and graphical pies for visual representations.
         - View service's uptime summary and detail reports.
         - View reports.

ADMIN FUNCTIONS:
   * User List - View/delete existing member details as well as the ability to manually upgrade account type and adding sms credits.
   * Common settings - setup paypal email and admin email settings.
   * SMS Settings - Configure sms gateways settings and sms alert message templates.
   * Server Management - Admin can add/edit server monitoring locations.
   * Email Templates Manager.
   * Countries Manager - Add/edit/delete countries.
   * States Manager - Add/edit/delete states.
   * FAQ Manager - Admin can add/edit/delete FAQs.
   * Membership Manager - Add custom membership packages. Admin can also edit/delete existing membership packages.
   * Built-in customer support ticket system - Members can send support tickets to the admin which will be displayed in this page where the admin can respond back to the members.
   * Add/edit/delete customer testimonials.
   * Change admin password.
Stephen Stagg
This shows uptime and load average (you could replace the exec line with a file_get_contents or similar)
<?php

$uptime = trim(exec("cat /proc/uptime"));
/*D*/print_r($uptime);
echo "<br/>";
$uptime = explode(" ", $uptime);
$idletime=$uptime[1];
$uptime=$uptime[0];


$day=86400;
$days=floor($uptime/$day);
echo "Up: $days days<br/>";
$utdelta=$uptime-($days*$day);

$hour=3600;
$hours=floor($utdelta/$hour);
echo "$hours hours<br/>";
$utdelta-=$hours*$hour;

$minute=60;
$minutes=floor($utdelta/$minute);
echo "$minutes minutes<br/>";
$utdelta-=round($minutes*$minute,2);

echo "$utdelta seconds<br/>";

echo '<b>Load Average</b><br/>';
echo round((1-($idletime/$uptime))*100,3);
echo "%";
?>
Paul
History of Uptime
The above is helpful but what I really want is a history of uptime that shows periods of downtime over the last week.  Is that possible with PHP?
Thanks,
Paul
Danijel
can somebody write some uptime script for irc server if that is posible ofcours Smile

tnx!
xxxxxxx
Here is one I use for windoz. make a batch file and call it with a variable that you post to this. Or make the batch file include multiple servers.  You may have to DL the uptime program from MS.


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

<?php
$test=`c:\winnt\system32\uptime2.bat $server`;
echo "<pre>$test</pre>";

?>


batch file.



@echo off

uptime.exe %1


Flavian


<?php
// ==============================
// Server Uptime And Hardware Information |
// ==============================
?>

<html>
<head>
<title><?php echo $SERVER_NAME; ?> - Server Information</title>
<STYLE type=text/css>
BODY { FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: Verdana,arial, helvetica, serif; margin : 0 0 0 0;}
</STYLE>
</head>
<body>
<pre>
<b>Uptime:</b>
<?php system("uptime"); ?>

<b>System Information:</b>
<?php system("uname -a"); ?>


<b>Memory Usage (MB):</b>
<?php system("free -m"); ?>


<b>Disk Usage:</b>
<?php system("df -h"); ?>


<b>CPU Information:</b>
<?php system("cat /proc/cpuinfo | grep \"model name\\|processor\""); ?>
</pre>

<br>
<br>
</body>
</html>


it will tell u which server ur usin, wats d uptime , load, user connected, disc usage

Hope this will help
Cosmin
Here is the uptime script that I use for my NetBSD 2.1 box:
$uptime = exec("uptime");
$uptime = split(" ",$uptime);
$days = $uptime[4];
$time = split(",",$uptime[7]);
if (sizeof($hourmin = split(":",$time[0])) < 2){ ;
$hours = "0";
$mins = $hourmin[0];
} else {
$hourmin=split(":",$time[0]);
$hours = $hourmin[0];
$mins = $hourmin[1];
}
$calcuptime =  "Uptime: ".$days." days ".$hours." hours ".$mins." mins" ;
echo $calcuptime;
Hope it helps!
Jonathan Nathanson
http://www.xenocafe.com/tutorials/php/realtime_server_uptime/index.php

download the file it has one that uses fread instasd of exec
Jason
Hey Guys, I have a PHP script that will work for your problems. It has been tested on Free BSD 5.x and WORKS.

Heres the code:

$uptime = exec("uptime");
$uptime = split(" ",$uptime);
$days = $uptime[3];
$time = split(",",$uptime[5]);
if (sizeof($hourmin = split(":",$time[0])) < 2){ ;
$hours = "0";
$mins = $hourmin[0];
}
else {
$hourmin=split(":",$time[0]);
$hours = $hourmin[0];
$mins = $hourmin[1];
}

This has some logic in case your box shows uptime like this:
12:51AM  up 2 days, 52 mins, 1 user, load averages: 0.00, 0.01, 0.00

Hope this helps..

Magyoi
stefan
Sad when I put in the script and uploaded it, it did nothing it was just blank Neutral
Salih
<?php
$uptime = exec("cat /proc/uptime");
$uptime = split(" ",$uptime);
$uptime = $uptime[0];
?>
<html>
<head>
<script language="javascript">
var upSeconds=<?php echo $uptime; ?>;
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" : " Gün") + ", ";
 }
 if (hours > 0) {
   uptimeString += hours;
   uptimeString += ((hours == 1) ? " hour" : " Saat") + ", ";
 }
 if (mins > 0) {
   uptimeString += mins;
   uptimeString += ((mins == 1) ? " minute" : " Dakika") + ", ";
 }
 uptimeString += secs;
 uptimeString += ((secs == 1) ? " second" : " Saniye");
 uptime.innerHTML = uptimeString;  upSeconds++;  setTimeout("doUptime()",1000);
}
</script>
</head>
<body onLoad="doUptime();">

<div id="uptime" style="font-weight:bold;">&nbsp;</div>

</body>
</html>
tiga
is there any scripts for windows server 2003?
i no, eeww, but thats all i have at the moment.
Steph
I notice that all of these solutions use exec which is pretty insecure.  Also, many hosts disable that function for this reason.

Is there a way to accomplish this without using exec or forcing cron jobs that would suck server resources?

Thanks
Andrius Ilgunas
err....cdm.  I have fat fingers tone, sorry about that.
Andrius Ilgunas
For those running FreeBSD, cdw's php/java/dhtml script will not run since we don't have a /proc/uptime.  

Instead, we have sysctl and you can use the following code:



<?php

$s = explode( " ", exec("/sbin/sysctl -n kern.boottime") );
$a = str_replace( ",", "", $s[3]);
$uptime = time() - $a;    

?>

cdm
http://www.xenocafe.com/tutorials/php/realtime_server_uptime/index.php
Raymond Marx

I am using this also.

Is it also possible to monitor more than one server with this command.

thanks
Daniel, 4WebHelp Team Member
OpTimuS-PrImuS: Sorry, I don't know of such a script and your guess is as good as mine as to where to find one.

Unfortunately this is not a subject which relates to our website.
OpTimuS-PrImuS
its for dal.net server a search one script for monitor dal.net server
Daniel, 4WebHelp Team Member
OpTimuS-PrImuS: No, not unless your IRC server runs Unix.

Pascal: That would require something other than PHP (Flash, Javascript, Java, whatever). Besides I don't really see the point...
Pascal
Hi, nice script, but I want to know if their's a way to see the time in real time...I mean...you see the second going up, without refreshing the page
OpTimuS-PrImuS
execelnet script but you have one script for uptime  irc server ?
Daniel, 4WebHelp Team Member
paux: Your tip is great, but note that not everyone has access to that file if they are on a shared server.
paux
On Linux, take a look into the virtual file /proc/uptime, which contains the uptime in seconds followed by the idle-time in seconds, e.g. "4300622.24 4251104.68"

You can then divide the first number (here: 4300622) twice by 60 and once by 24 to get the number of days (here: 49.775718). Similar calculations (with help of the modulo-operator "%") give you hours, minutes and seconds.

It's easy then to create an output like "This server is up 49 days 18 hours 37 minutes and 2 seconds"

I've done it this way:

<?php
$uptime = shell_exec("cut -d. -f1 /proc/uptime");
$days = floor($uptime/60/60/24);
$hours = $uptime/60/60%24;
$mins = $uptime/60%60;
$secs = $uptime%60;
echo "This server is up $days days $hours hours $mins minutes and $secs seconds";
?>
Great little script.
I was looking for something just like this. I don't like the straight uptime output like:  5:46PM  up 4 days,  7:19, 1 user, load averages: 0.05, 0.05, 0.06

It's ugly and hard non techies to understand.

You've kept it simple and easy to read and I thank you.

-Tom

Add a new comment

This page is © Copyright 2002-2024, 4WebHelp. It may not be reproduced without 4WebHelp's prior permission.