Click to See Complete Forum and Search --> : Online or Offline?
cdn415
05-26-2003, 03:34 PM
Is there a way in php to tell a user if a mirror is online or offline without me changing it? I also want to know if there is a way to automatically redirect to the one(or either one) that is online? Here is an example of a page I have found that has/does this: http://home.hccnet.nl/h.edskes/mirror.htm
Thanks.
You should probably use CGI to Ping the server. That is the best way. PHP doesn't have a Ping function, so this can only be done in CGI.
cdn415
05-26-2003, 04:04 PM
Well do you know the code for the CGI one?
Sure don't. Try the CGI forum.
Nevermore
05-26-2003, 04:43 PM
Actually you can ping in PHP (although strictly it isn't PHP...)
$host="www.yoursite.com";
$ping=system("ping $host");
echo $ping;
That should do the trick, although the results won't be brilliantly formatted.
If it's not strictly PHP, then what is it?
AdamBrill
05-26-2003, 05:52 PM
I would suggest that you use this instead:<?PHP
$file = "http://www.yourdomain.com/index.htm";
$fp = @file($file);
if($fp){
echo "server up!";
}else{
echo "server down!";
}
?>Change the $file to be a file that is on your server. Then it will tell you if the server that the file is on is up or down. Cijori's method would be fine, but it won't work on all servers...
You also don't need to use a ping (although that is the best way). You could simply try to open a file on the server and detect whether or not it opened or not... Something like:
$file = "http://www.youdomain.com/online.txt"; //set this to some page that you know is on your server
$online = @file($file);
if ($online) {
#page is online
}
else {
#page is offline
}
AdamBrill posted while I was typing up a reply... :D
cdn415
05-26-2003, 07:19 PM
Thanks guys. I will try it to see if it works.
Nevermore
05-27-2003, 04:39 AM
Originally posted by Jona
If it's not strictly PHP, then what is it?
It is actually running the ping program which is present on about 99% of servers via PHP.
I have the Ping program in my WINDOWS folder of my computer. Could I upload that and edit my Apache handlers to run the program when PHP executes it with the system() command? Or would I just have to install C or something?
Nevermore
05-27-2003, 10:43 AM
I don't know - have you tried running ping without changing anything?
Yes, I tested your original code and my result was a completely, 100% blank page.
Jona