Ping a server via HTML/PHP

Soldato
Joined
31 Mar 2006
Posts
3,272
Location
Gravesend, Kent
Hey everyone!

I'm trying to create a page on my home apache server that will ping (or similar) my dedicated server, and the echo some text to say whether or not its online. Is this possible?

I tried Google but nothing there :(


Matt
 
Code:
<?php

// url
echo chkuri("www.google.com");


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


?>
http://www.hotscripts.com/Detailed/9326.html

Found this via Google ;). I've edited it to work automatically - just alter the URL to either an IP or domain.

It doesn't ping in the traditional sense, it tries to open a connection to the website but that's good enough.
 
Back
Top Bottom