hammerslane
11-26-2003, 05:38 AM
ok if you were around yesterday, then you might remember i wanted a ping script to test if a number of sites are working.
it took a couple of hours, and of you want to see what i found, then see the bottom of this post.
anyway. what i want to happen, is for the script below to be run every 10 minutes or so...
i don't know what kind of function i can use...
regards
<?
function chkuri($link){
$churl = @fopen("http://".$link,'r');
if (!$churl) {
$message="site link <b>http://$link <font color=\"red\"> is down!!</font></b><br><br>\n";
mail("hammerslane@example.com", "$link is down!!", "Do something\nOtherwise\nAll hell will break lose");
}else{
$message="site link <a href=\"http://$link\" target=_blank><b>http://$link</b></a> OK!<br>";
}
return $message;
}
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){
$time="down!!"; break;
}
$time=$time+round(($b-$a)*1000);
@fclose($churl);
}
if ($time=="down!!"){}else{if(($time/$packs)<3){$time="<3 ms";}else{$time=($time/$packs)." ms";}}
return $time;
}
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>";
?>
it took a couple of hours, and of you want to see what i found, then see the bottom of this post.
anyway. what i want to happen, is for the script below to be run every 10 minutes or so...
i don't know what kind of function i can use...
regards
<?
function chkuri($link){
$churl = @fopen("http://".$link,'r');
if (!$churl) {
$message="site link <b>http://$link <font color=\"red\"> is down!!</font></b><br><br>\n";
mail("hammerslane@example.com", "$link is down!!", "Do something\nOtherwise\nAll hell will break lose");
}else{
$message="site link <a href=\"http://$link\" target=_blank><b>http://$link</b></a> OK!<br>";
}
return $message;
}
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){
$time="down!!"; break;
}
$time=$time+round(($b-$a)*1000);
@fclose($churl);
}
if ($time=="down!!"){}else{if(($time/$packs)<3){$time="<3 ms";}else{$time=($time/$packs)." ms";}}
return $time;
}
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>";
?>