View Full Version : sever status checker
wildy
05-30-2007, 01:24 AM
does anyone have a script that will show wether a server is online or offline on my site?
if you know a site where i can find this please give me a link to it, or if you have the script send it to me at fivenames6@msn.com
nuweb
06-01-2007, 08:36 PM
I coded this for you:
<?php
$onlineimageurl = "http://yourdomain.com/serveronline.gif";
$offlineimageurl = "http://friendswebsite.com/serveroffline.gif";
if (@GetImageSize($onlineimageurl)) {
echo '<img src="'.$onlineimageurl.'">';
} else {
echo '<img src="'.$offlineimageurl.'">';
}
?>
It checks if the image exsists, if it dont then it will show the server offline image.
ENJOY!!
UnlimitedMB
06-04-2007, 01:24 AM
The problem with nuweb's code is if the server being tested is down the entire script will hang until the connection times out, thus making your site appear to load extremely slowly.
This also happens if one of your RSS feeds (or any external urls loaded by php code) is down.
nuweb
06-06-2007, 04:47 PM
As Requested, Here is a modified code which makes use of set_time_limit() . This allows you to set a limit to the time it should take for a load.
ENSURE the code is in a seperate php document, and use include to get the result, otherwise your forum or whaterver will have 3 secconds to load.
<?php
set_time_limit(3);
$onlineimageurl = "http://yourdomain.com/serveronline.gif";
$offlineimageurl = "http://friendswebsite.com/serveroffline.gif";
if (@GetImageSize($onlineimageurl)) {
echo '<img src="'.$onlineimageurl.'">';
} else {
echo '<img src="'.$offlineimageurl.'">';
}
?>
UnlimitedMB
06-06-2007, 05:06 PM
set_time_limit will not fix this problem, it only effects processing time, it doesnt count the time spent waiting on network connections.
The only way is to use fsockopen with a time limit.
nuweb
06-08-2007, 11:22 PM
As UnlimitedMB pointed out, I never tested it whould work.
I thought it whould do, m re ive used itbefore.
--
A Time Limit on fsockopen whould work, but im not sure how to do that.
cr0wonline
06-09-2007, 01:29 AM
An easy way to do this (not the best way, but it works) is to use this:
<table align="center" style="width: 250px;border: 1px solid #000000" cellpadding="0">
<tr>
<td style="background-image: url(http://www.site.com/offline.jpg)">
<table>
<tr>
<td style="background-image: url(http://www.othersite.com/online.jpg)">
</td>
</tr>
</table>
</td>
</tr>
</table>
UnlimitedMB
06-10-2007, 03:26 AM
Heres one for you.
But seriously avoid these type of things if you can.
It just wastes resources.
<?php
function is_online($host){
$fp = @fsockopen($host, 80, $errno, $errstr, 5);
if (!$fp) {
return false;
} else {
@fclose($fp);
return true;
}
}
if (is_online("www.google.com")){
echo "google is up";
}
?>
vBulletin® v3.8.4, Copyright ©2000-2012, Jelsoft Enterprises Ltd.