Forum Moderators: coopster

Message Too Old, No Replies

how to make sure external URL is reachable?

determiningg if another site's contents can be reached

         

lli2k5

7:05 am on Sep 11, 2006 (gmt 0)

10+ Year Member



Is there any simple method in php to determine if a url from a website is reachable?

This is so that if your website has to load content from another URL, is there a failsafe method for the other parts of your website to load even if that one part is down?

barns101

8:43 am on Sep 11, 2006 (gmt 0)

10+ Year Member



You could use fsockopen() [php.net] to open a socket to the external page and then use strpos() [php.net] to check the headers to make sure that HTTP/1.1 200 OK was returned.

Vastio

6:13 am on Sep 13, 2006 (gmt 0)

10+ Year Member



I think I found this function not too long ago on the PHP.net website:

function url_exists($url) {
$handle = @fopen($url, "r");
if ($handle === false)
return false;
fclose($handle);
return true;
}