Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

dns_get_record() with timeout?

2,017 views
Skip to first unread message

Simon

unread,
Nov 16, 2012, 10:04:11 AM11/16/12
to
Hi,

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
seconds).

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
timeouts.

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

Simon

Salvatore

unread,
Nov 16, 2012, 10:23:46 AM11/16/12
to
On 2012-11-16, Simon <b...@example.com> wrote:
> 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
> timeouts.

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:

http://www.php.net/manual/en/function.gethostbyaddr.php#46869

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

Raul Molnar

unread,
Feb 13, 2023, 11:09:09 AM2/13/23
to

Hi,

See

https://github.com/bluelibraries/dns

This will help you to control your timeout (and more)/

J.O. Aho

unread,
Feb 13, 2023, 12:33:32 PM2/13/23
to
On 2/13/23 17:09, Raul Molnar wrote:
>
> Hi,
>
> See

I think you didn't see "November 16, 2012", I doubt the OP been waiting
for your reply for 3741 days.


Raul Molnar

unread,
Mar 24, 2023, 1:05:49 PM3/24/23
to
https://github.com/bluelibraries/dns

I've added a playground for it

https://gethostinfo.com/records

It should be short timeout here to maximum 10 seconds.

Jerry Stuckle

unread,
Mar 24, 2023, 1:25:19 PM3/24/23
to
I think your point went way over his head, J.O. :)

--
==================
Remove the "x"'s from my email address
Jerry Stuckle
stuckle...@gmail.com
==================

J.O. Aho

unread,
Mar 24, 2023, 4:58:34 PM3/24/23
to
On 24/03/2023 18:24, Jerry Stuckle wrote:
> On 2/13/2023 12:33 PM, J.O. Aho wrote:
>> On 2/13/23 17:09, Raul Molnar wrote:
>>>
>>> Hi,
>>>
>>> See
>>
>> I think you didn't see "November 16, 2012", I doubt the OP been
>> waiting for your reply for 3741 days.
>>
>>
>
> I think your point went way over his head, J.O. :)

:)
Too big numbers for him to understand, but more important to post github
url.

--
//Aho

0 new messages