I am looking for a fast wat to test if a domain name is in use, hence has a site attached to it. I have a huge list of domain names and need to check which ones have a site attached to it or not.
If I know that there is a site attached to it then I don't need to do any time consuming whois lookups, etc.
My initial idea was to check for HTTP header code and see if the header codes return 200, 301, 302... if is is something else there is a high chance that there is no site attached or that the domain name is available. The code snipper I am using is:
$headers = @get_headers( $url);
$headers = (is_array($headers)) ? implode( "\n ", $headers) : $headers;
return (bool)preg_match('#^HTTP/.*\s+[(200|301|302)]+\s#i', $headers);
However this process is pretty slow.
Next I've tried using the PHP function checkdnsrr to check if a DNS record exist. I am using the following code snipper.
if (checkdnsrr($domain . ".", "A") == false) {
echo "Domain might be available";
} else {
echo "Domain is in use";
}
Unfortunately it gives me a lot of "false" information saying that the domain might be available. The same goes for the following code snippet:
if (gethostbyname($domain) != $domain) {
echo "DNS Record found";
} else {
echo "NO DNS Record found";
}
A WHOIS lookup is a possibility also however with all the new TLD (.frl, .xyz, etc.) this might be a huge task to setup.
Another idea I had was to ping the domain name in question and if I get a response I know the domain name is "in use". Not sure if this is the best approach therefor I am asking you is there a a fast but more reliable way to check if domain is in use (or registered)?