I have seen the wildest answers to this question and would really hate to see some struggle with it. Many solutions use a whois lookup which is very slow and in some cases could get your IP address temporarily banned. My solution goes right at the source - for a domain to be registered it needs to have a NS (nameserver) record in the DNS so that it can be resolved to an IP address. Here is an example that uses the is_domain_available function and finds the available domains from sports2000.com .. sports2099.com. <pre> <?php // This is the key one [B]function is_domain_available($domain) { // quickly check for NS record return (count(dns_get_record($domain, DNS_NS)) == 0); }[/B] list($usec, $sec) = explode(' ', microtime()); $script_start = (float) $sec + (float) $usec; for($i=0; $i<100; $i++) { $domain = sprintf("sports2%03d.com", $i); if (is_domain_available($domain)) { print "$domain is free!\n"; } } list($usec, $sec) = explode(' ', microtime()); $script_end = (float) $sec + (float) $usec; $elapsed_time = round($script_end - $script_start, 5); print "Elapsed time: $elapsed_time\n"; ?> </pre> Code (markup): This function checked all 100 domains in 9 seconds. I am open to suggestions/ideas on how to improve speed. Has anyone tried connecting directly to OpenDNS servers?
.. ++$i is faster than $i++ echo is faster than print $domain = sprintf("sports2%03d.com", $i); is useless and slow..
silotka, thank you for the feedback! The question I am really concerned about is how to speed up is_domain_available. What is a good alternative for sprintf?