View Full Version : cgi - determine if site is down......
qwertyuiop
02-19-2005, 03:27 AM
Hi,
I'm looking for a really simple CGI script that does the things below:
1) Finds out if a certain site is "down"
2) if it is, then display certain html
3) if not then display another html
i spent a long time lookign for it, but cant find one.
thanks
mlseim
02-19-2005, 04:46 AM
I found this one ... it's PHP, not Perl.
I just uploaded it and ran it. It works, but haven't modified it
to be used within another PHP script.
maybe with some modification, a Perl script could call it, and the PHP
script would return back a status to the Perl script.
Use it sort of like a function or subroutine. It has some possibilities.
Here is what the PHP script does .... go to this link and enter your own URL.
http://www.catpin.com/status.php3
==========================================================
<?php
function chkuri($link){
$churl = @fopen("http://".$link,'r');
if (!$churl) {
$meldung="site link <b>http://$link <font color=\"red\"> is down!!</font></b><br><br>\n";
}else{
$meldung="site link <a href=\"http://$link\" target=_blank><b>http://$link</b></a> OK!<br>";
}
return $meldung;
}
function ping($link){
$packs=5;
for ($tt=0;$tt<=$packs;$tt++){
$a=getmstime();
$churl = @fsockopen(server($link), 80, &$errno, &$errstr, 20);
$b=getmstime();
if (!$churl){
$zeit="down!!"; break;
}
$zeit=$zeit+round(($b-$a)*1000);
@fclose($churl);
}
if ($zeit=="down!!"){}else{if(($zeit/$packs)<3){$zeit="<3 ms";}else{$zeit=($zeit/$packs)." ms";}}
return $zeit;
}
function server($link){
if(strstr($link,"/")){$link = substr($link, 0, strpos($link, "/"));}
return $link;
}
function getmstime(){
return (substr(microtime(),11,9)+substr(microtime(),0,10));
}
function correcturl($link){
return str_replace("http://","",strtolower($link));
}
function selfnam(){
global $PHP_SELF;
return basename($PHP_SELF);
}
$link=correcturl($link);
echo "ping server <b>http://".server($link)." (".ping($link).")</b><br>";
echo chkuri($link);
echo "<form action=".selfnam()." method=get>";
echo "http://<input type=input name=link value=\"$link\" size=60>";
echo "<input type=submit name=check value=check>";
echo "</form>";
?>
qwertyuiop
02-19-2005, 06:17 AM
thanks for the speeedy response.
I was looking for a cgi script so that I could use SSI (like: <!--#include file="status.pl" -->). So if the site is down, then it would display a notice about it.
The php script you found works, but i dont see how its gonna work in my situation. You have to type the url of the site, then it tells you if it's up or down......its kinda confusing.
thanks for the help though.
mlseim
02-19-2005, 07:06 PM
That's the reason I mentioned that the PHP script would need to be
modified. So I modified it. The thing can work just like a sitemeter
on your website. :thumbsup:
Within your webpage, you have a javascript that calls the PHP script.
The PHP script substitutes a .gif image for the javascript.
See this example of a site that is active:
http://www.catpin.com/ping.html
I figured out that you can only have it check once for each
page refresh, so the javascript can only be used once on a page.
So, I made a second page showing a bad site:
http://www.catpin.com/ping2.html
Below is the PHP script - modified.
You will need to create your own images and change the script accordingly.
The Javascript can be viewed on the pages shown in the links above.
I have read some discussion on this topic. It seems there is some
argument about the difference between a Server being down, and
the HTTP Server being down. Will the PHP script show a site as
"up", when in fact the server is running, but the HTTP Server is "down"?
I have no way to test that ... :o
=======================================================
<?php
function chkuri($link){
$churl = @fopen("http://".$link,'r');
if (!$churl) {
$meldung="http://www.catpin.com/site_off.gif";
}else{
$meldung="http://www.catpin.com/site_ok.gif";
}
return $meldung;
}
function ping($link){
$packs=5;
for ($tt=0;$tt<=$packs;$tt++){
$a=getmstime();
$churl = @fsockopen(server($link), 80, &$errno, &$errstr, 20);
$b=getmstime();
if (!$churl){
$zeit="down!!"; break;
}
$zeit=$zeit+round(($b-$a)*1000);
@fclose($churl);
}
if ($zeit=="down!!"){}else{if(($zeit/$packs)<3){$zeit="<3 ms";}else{$zeit=($zeit/$packs)." ms";}}
return $zeit;
}
function server($link){
if(strstr($link,"/")){$link = substr($link, 0, strpos($link, "/"));}
return $link;
}
function getmstime(){
return (substr(microtime(),11,9)+substr(microtime(),0,10));
}
function correcturl($link){
return str_replace("http://","",strtolower($link));
}
function selfnam(){
global $PHP_SELF;
return basename($PHP_SELF);
}
$link=correcturl($link);
$url=chkuri($link);
Header("Location: $url");
?>
qwertyuiop
02-20-2005, 01:05 AM
i kinda get this now.
but how will it work if javascript is disabled? it won't, right?
---------------------------------------------------------
i was looking around for some help, and I found something called xssi.
it seems like it will work for me, but i dont know the correct way of doing it.
here's an outline:
<!--#if expr="site is down" -->
<p>Unfortunately, this feature is temporarily unavailable.</p>
<!--#else -->
<p>Since the site is up, this is where the feature goes!</p>
<!--#endif -->
i dont know what to put in the red area.....
thanks for all the help!
ill try look into the php sum more.
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.