dns_get_record() with timeout?

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

I have a cron job that runs in the background to check various urls
entered by users.

One of the job is to get the ip addresses of the urls given.

For that, the function dns_get_record(),
(http://php.net/manual/en/function.dns-get-record.php ), works great.
I can get the IP addresses of the site, or even if the site is
'broken/unavailable', (or just garbage).

The only issue is that there does not really seem to be a way of adding
timeout to the function.

So in some cases, the functions waits for over 1 minute, if not longer,
(I have seen suggestions that the function should not wait more than 20

Would anybody know of a fairly generic way of getting the IP addresses
of a site, (ipv4 and ipv6 when available), while protecting myself from

And, (maybe more importantly), does anybody know if it is possible for
the function dns_get_record( ... ) to never return?
Could an invalid domain/string cause the function to misbehave altogether?

Many thanks


Re: dns_get_record() with timeout?

Quoted text here. Click to load it

You have to write your own function that will build a UDP packet to
query a DNS server, call the socket_set_timeout() function to set a
timeout value, send the UDP packet, and hope that you get a response.

An example of how you can do this is located at php.net:


Blah blah bleh...
GCS/CM d(-)@>-- s+:- !a C++$ UBL++++$ L+$ W+++$ w M++ Y++ b++

Site Timeline