/    Sign up×
Community /Pin to ProfileBookmark

Fastest way of getting a domain’s IP?

Hi

I have this in a function:

[code=php]
$hosts = gethostbynamel($domain);
if (is_array($hosts)) {
$IP = $hosts[0];
}
[/code]

I’m fetching about 2 million $domain from a database and want to get the ip of the domain. Sometimes the domain is just garbage for example “yhujgga”, or even a IP-address.

The gethostbynamel() seems to take a while sometimes, as I guess a dns-lookup (it is a dns-lookup?) would do. Are there any faster ways of getting the ip of a domain (well, a domain in most cases, sometimes just garbage)? Naturally the above would take a while on 2 million domain names, and I really would like to speed it up…

Thanks
Lubox

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@LuboxauthorMar 13.2007 — Ok, let me try to ask it a little bit different:

Any way of getting the IP address of a domain name which let me add a timeout value (not PHP set_time_limit)? Maybe something with fsockopen, or?

The problem is that some of the gethostbynamel() seems to take really long time once in a while, and it would help if I could add a timeout of for example 5 seconds or something, and then continue my script..

Any suggestions?

Thanks

Lubox
Copy linkTweet thisAlerts:
@bokehMar 13.2007 — You would need to open a socket in non blocking mode. Alternatively use the PEAR dns class and set a timeout. In theory the DNS should deal with this issue but you need to remember DNS lookups take time. Sometimes it even takes several seconds just to raise a root server. Try running a few domains through my DNS checker in my signature and you will see what I mean.
×

Success!

Help @Lubox spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.24,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...