27 December 2013

Check Website Is Available(Running) Or Not

This script will help you to check Domain Status (Website is available or not) using cURL...
This function will return True if Domain(Website) is Available, return False if not Available...

/**
 * To Check Domain Status (available or not).
 * @param $domain --> Site's Url.
 * @return true --> if domain is available(Running), false --> if not available.
 */
function checkDomainStatus($domain)
{
 //check, if a valid url is provided
 if(!filter_var($domain, FILTER_VALIDATE_URL)){
  return false;
 }

 //initialize curl
 $curlInit = curl_init($domain);
 curl_setopt($curlInit,CURLOPT_CONNECTTIMEOUT,10);
 curl_setopt($curlInit,CURLOPT_HEADER,true);
 curl_setopt($curlInit,CURLOPT_NOBODY,true);
 curl_setopt($curlInit,CURLOPT_RETURNTRANSFER,true);

 //get answer
 $response = curl_exec($curlInit);
 curl_close($curlInit);
 if ($response){
  return true;
 }
 return false;
}

No comments:

Post a Comment