cULR Library PHP : Check website status
Saturday, March 6, 2010 11:54Posted in category CURL PHP Examples
function checkDomainLiveStatus($url)
{
$agent = "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)";$ch=curl_init();
curl_setopt ($ch, CURLOPT_URL,$url );
curl_setopt($ch, CURLOPT_USERAGENT, $agent);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch,CURLOPT_VERBOSE,false);
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
$page=curl_exec($ch);
//echo curl_error($ch);
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if($httpcode>=200 && $httpcode<300) return true;
else return false;
}
if(checkDomainLiveStatus("http://www.yourdomain.com")) {
echo "Website OK"."n";
} else { /* if website is down*/
echo "Website DOWN";
}
You can follow any responses to this entry through the RSS 2.0 feed.
You can leave a response, or trackback from your own site.



Liaseanemia says:
March 7th, 2010 at 10:56 am
Many thanks!
Lita Bula says:
March 8th, 2010 at 5:22 pm
This is an interesting blog you have her but I can’t seem to find the RSS subscribe button.
imran says:
March 9th, 2010 at 10:25 am
Please have a look at the bottom of the website, you got it ?