Since my server/host does not allow me to use ping, I wrote a simple piece of code to to simulate ping.
By opening a file from the remote server and reading one line. If the file/line cannot be read, the script sends me an email.
The problem is that if the line cannot be read, PHP sends an error to the browser :
"Warning: fopen("http://66.32.85.180/test.php", "r") - Inappropriate ioctl for device in /home2/netone/public_html/Pingit.php on line 16
Couldn't open Pinged file"
and the script stop executing/will not send me an email.
Can anyone think of an easy way to overcome this ?
test.php
<?
echo "Success";
?>
Pingit.php
// open the file and read the line:
$file="http://66.32.85.180/test.php";
line16 $fp=fopen("$file", "r") or die ("Couldn't open Pinged file");
$line=fgets($fp, 1024);
fclose($fp);
//if the line cannot be read, notify me in an email:
if(!empty($line)) {
mail("pedro@netzero.net","ping error", "could not read file", "FROM: ping@netzero.net");
}
Thanks,
Peter