iwato Posted June 25, 2011 Share Posted June 25, 2011 BACKGROUND: The following code takes an ordinary domain name, reverses it, concatenates it to another domain name via a dot, and performs a domain name record check. Apparently it is suppose to tell you whether or not a particular IP address has been black-listed. PROBLEM: What I find troubling is the length of time that it takes to process the code -- more than a half-minute. As I am hardly familiar with blacklisting, I am hoping that someone can explain the very long delay. <?php function check_dnsbl($ip) { $dnsbl_check=array("bl.spamcop.net","list.dsbl.org", "sbl.spamhaus.org",'xbl.spamhaus.org'); if($ip){ $rip=implode('.',array_reverse(explode(".",$ip))); foreach($dnsbl_check as $val){ if(checkdnsrr($rip.'.'.$val.'.','A')) return $rip.'.'.$val; } } return false; }?> Roddy Link to comment Share on other sites More sharing options...
jeffman Posted June 26, 2011 Share Posted June 26, 2011 I've never used checkdnsrr before, so I tried it. Sure enough, there is noticeable lag time. I suppose it varies from connection to connection. Link to comment Share on other sites More sharing options...
Ingolme Posted June 26, 2011 Share Posted June 26, 2011 I suppose it takes long because you're sending several requests to remote DNS servers and waiting for all the responses. Link to comment Share on other sites More sharing options...
boen_robot Posted June 26, 2011 Share Posted June 26, 2011 If you want to avoid the delay, you'd have to build a custom DNS cache - a list of IPs residing locally that you check before resolving the domains and updating the IP list regularly, or better yet, use dns_get_record(), keep the TTL and refresh the cache based on it (like real DNS caches do). Why doesn't PHP have a built in DNS cache is beyond me. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.