I need to create a function that returns if a URL is reachable or valid.
I am currently using something like the following to determine a valid url:
static public function urlExists($url)
{
$fp = @fopen($url, 'r');
if($fp)
{
return true;
}
return false;
}
It seems like there would be something faster, maybe something that just fetched the page header or something.
You could check http status code.
Here is a code you could use to check that an url returns 2xx or 3xx http code to ensure the url works.
Hope this helps!