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.
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>
Any idea why I'm only getting a comma?
i had to download the uptime.exe from ms, just search for it on their site..
Uptime.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:
uptime.exe %1
<?php
$s = explode( " ", exec("/sbin/sysctl -n kern.boottime") );
$a = str_replace( ",", "", $s[3]);
$uptime = time() - $a;
?>
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.
<?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 "%";
?>
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
tnx!
<?php
$server = $_POST['server'];
?>
<body>
<?php
$test=`c:\winnt\system32\uptime2.bat $server`;
echo "<pre>$test</pre>";
?>
batch file.
@echo off
uptime.exe %1
<?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
$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;
download the file it has one that uses fread instasd of exec
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:
Hope this helps..
Magyoi
$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;"> </div>
</body>
</html>
i no, eeww, but thats all i have at the moment.
Is there a way to accomplish this without using exec or forcing cron jobs that would suck server resources?
Thanks
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;
?>
I am using this also.
Is it also possible to monitor more than one server with this command.
thanks
Unfortunately this is not a subject which relates to our website.
Pascal: That would require something other than PHP (Flash, Javascript, Java, whatever). Besides I don't really see the point...
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:
$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";
?>
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