Can i ping from one site to another to see if its online? I want to check if a site is online, if the site isn't then i want the visitors to be guided to another.
Who can help me?
Thanks, Mark
One way to do this is to try and fopen() the site.
$site_one = "http://www.mysite.com"; $site_two = "http://www.myothersite.com";
if(@fopen($site_one, "r")) { Header("Location: $site_one"); } else { Header("Location: $site_two"); }
.. although it's a bit dirty and probably slow.
/Mike
probably slow
Sure, but if all you care about is "is this site up", just use fsockopen() to try to open a connection to port 80 on the machine, and you can then specify your own timeout.
<? $query = fsockopen("123.456.789.01", 80, &$errno, &$errstr, 10); if(!$query) { echo "The site is up\n"; } else { echo("The site is down\n"; } } ?>
Yes, but isn't the sense of the test reversed? The ! doesn't belong there, the way I read it.
Also, you might want to close the socket after you're done with it (if it does succeed.)
Thanks,
I will try this ASAP.
Mark