public function isDomainAvailable($url, $timeOut = 7)
    {
        // Init curl
        $ch = curl_init($url);
        curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13');
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeOut);
        curl_setopt($ch, CURLOPT_HEADER, 1);
        curl_setopt($ch, CURLOPT_HTTPGET, 1);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
        curl_setopt($ch, CURLOPT_MAXREDIRS, 5);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
        
        // Get the response
        $response    = curl_exec($ch);
        $httpCode    = curl_getinfo($ch, CURLINFO_HTTP_CODE);
        $curlError   = curl_error($ch);
        $curlErrorNo = curl_errno($ch); 
        curl_close($ch);

        //Curl response error
        if($curlErrorNo) {
            if(in_array($curlErrorNo, array(CURLE_TOO_MANY_REDIRECTS))) {
                if(defined("BROKEN_LINKS_LOG") && BROKEN_LINKS_LOG) {
                    error_log("Broken links: Could not probe url " . $url . " due to a malfunction of curl [" . $curlErrorNo. " - " . $curlError . "]"); 
                }
                return true; //Do not log
            } else {
                if(defined("BROKEN_LINKS_LOG") && BROKEN_LINKS_LOG) {
                    error_log("Broken links: Could not probe url " . $url . ", link is considerd broken [" . $curlErrorNo. " - " . $curlError . "]"); 
                }
                return false; // Do log
            }
        }

        if(defined("BROKEN_LINKS_LOG") && BROKEN_LINKS_LOG) {
            error_log("Broken links: Probe data " . $url . " [Curl error no: " . $curlErrorNo. "] [Curl error message:" . $curlError . "] [Http code: ".$httpCode."]"); 
        }
        
        //Validate
        if($response) {
            //Genereic codes 
            if($httpCode >= 200 && $httpCode < 400) {
                return true; 
            }

            //Specific out of scope codes 
            //401: Unathorized
            //406: Not acceptable
            //413: Payload to large
            //418: I'm a teapot
            if(in_array($httpCode, array(401, 406, 413))) {
                return true;
            }
        }

        return false;
    }
public function isDomainAvailable($url, $timeOut = 7)
    {
        // Init curl
        $ch = curl_init($url);
        curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13');
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeOut);
        curl_setopt($ch, CURLOPT_HEADER, 1);
        curl_setopt($ch, CURLOPT_HTTPGET, 1);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
        curl_setopt($ch, CURLOPT_MAXREDIRS, 5);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
        
        // Get the response
        $response    = curl_exec($ch);
        $httpCode    = curl_getinfo($ch, CURLINFO_HTTP_CODE);
        $curlError   = curl_error($ch);
        $curlErrorNo = curl_errno($ch); 
        curl_close($ch);

        //Curl response error
        if($curlErrorNo) {
            if(in_array($curlErrorNo, array(CURLE_TOO_MANY_REDIRECTS))) {
                if(defined("BROKEN_LINKS_LOG") && BROKEN_LINKS_LOG) {
                    error_log("Broken links: Could not probe url " . $url . " due to a malfunction of curl [" . $curlErrorNo. " - " . $curlError . "]"); 
                }
                return true; //Do not log
            } else {
                if(defined("BROKEN_LINKS_LOG") && BROKEN_LINKS_LOG) {
                    error_log("Broken links: Could not probe url " . $url . ", link is considerd broken [" . $curlErrorNo. " - " . $curlError . "]"); 
                }
                return false; // Do log
            }
        }

        if(defined("BROKEN_LINKS_LOG") && BROKEN_LINKS_LOG) {
            error_log("Broken links: Probe data " . $url . " [Curl error no: " . $curlErrorNo. "] [Curl error message:" . $curlError . "] [Http code: ".$httpCode."]"); 
        }
        
        //Validate
        if($response) {
            //Genereic codes 
            if($httpCode >= 200 && $httpCode < 400) {
                return true; 
            }

            //Specific out of scope codes 
            //401: Unathorized
            //406: Not acceptable
            //413: Payload to large
            //418: I'm a teapot
            if(in_array($httpCode, array(401, 406, 413))) {
                return true;
            }
        }

        return false;
    }
public function isDomainAvailable ( $ url , $ timeOut = 7 ) { // Init curl $ ch = curl_init ( $ url ) ; curl_setopt ( $ ch , CURLOPT_USERAGENT , 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13' ) ; curl_setopt ( $ ch , CURLOPT_CONNECTTIMEOUT , $ timeOut ) ; curl_setopt ( $ ch , CURLOPT_HEADER , 1 ) ; curl_setopt ( $ ch , CURLOPT_HTTPGET , 1 ) ; curl_setopt ( $ ch , CURLOPT_RETURNTRANSFER , 1 ) ; curl_setopt ( $ ch , CURLOPT_FOLLOWLOCATION , 1 ) ; curl_setopt ( $ ch , CURLOPT_MAXREDIRS , 5 ) ; curl_setopt ( $ ch , CURLOPT_SSL_VERIFYHOST , 0 ) ; curl_setopt ( $ ch , CURLOPT_SSL_VERIFYPEER , 0 ) ; // Get the response $ response = curl_exec ( $ ch ) ; $ httpCode = curl_getinfo ( $ ch , CURLINFO_HTTP_CODE ) ; $ curlError = curl_error ( $ ch ) ; $ curlErrorNo = curl_errno ( $ ch ) ; curl_close ( $ ch ) ; //Curl response error if ( $ curlErrorNo ) { if ( in_array ( $ curlErrorNo , array ( CURLE_TOO_MANY_REDIRECTS ) ) ) { if ( defined ( "BROKEN_LINKS_LOG" ) && BROKEN_LINKS_LOG ) { error_log ( "Broken links: Could not probe url " . $ url . " due to a malfunction of curl [" . $ curlErrorNo . " - " . $ curlError . "]" ) ; } return true ; //Do not log } else { if ( defined ( "BROKEN_LINKS_LOG" ) && BROKEN_LINKS_LOG ) { error_log ( "Broken links: Could not probe url " . $ url . ", link is considerd broken [" . $ curlErrorNo . " - " . $ curlError . "]" ) ; } return false ; // Do log } } if ( defined ( "BROKEN_LINKS_LOG" ) && BROKEN_LINKS_LOG ) { error_log ( "Broken links: Probe data " . $ url . " [Curl error no: " . $ curlErrorNo . "] [Curl error message:" . $ curlError . "] [Http code: " . $ httpCode . "]" ) ; } //Validate if ( $ response ) { //Genereic codes  if ( $ httpCode >= 200 && $ httpCode < 400 ) { return true ; } //Specific out of scope codes  //401: Unathorized //406: Not acceptable //413: Payload to large //418: I'm a teapot if ( in_array ( $ httpCode , array ( 401 , 406 , 413 ) ) ) { return true ; } } return false ; }
Test if domain is available with curl
@param string $url Url to check
@return bool
Test if domain is available with curl