Checking if the site resolve a DNS or not
You are doing way more than necessary, if all you want to verify is that the hostname resolves to an IP address.

gethostbyname() comes pretty close to doing the job:


  Returns the IPv4 address or a string containing the unmodified hostname on failure.


Actually, that's annoying.  Try gethostbynamel() instead:


  Returns an array of IPv4 addresses or FALSE if hostname could not be resolved.


So, you could just do

$url_parts = parse_url($url);
return gethostbynamel($url_parts['host']) ? true : false;




Note, however, that the gethostbyname() family of functions relies on the operating system to do the name resolution in whatever way it is configured.  Usually, that means using DNS.  However, it might also use a local hosts file, NIS, LDAP, Multicast DNS, etc.  dns_get_record() would actually perform a DNS lookup, independent of the machine's preferred name resolution mechanism.  If you want to go that route, then it looks like checkdnsrr($host, 'A') would be convenient.

The distinction is almost always inconsequential, but I thought I'd mention it since you specifically mentioned DNS resolution in your question.