468,766 Members | 1,312 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,766 developers. It's quick & easy.

gethostbyname slow

using the gethostbyname function seems to noticeably slow down pages.
some of the comments in php.net's gethostbyname entry suggest using a
version that caches the result, but those versions also only speedup
subsequent calls to gethostbyname - the first call is still as slow as
ever.

so is there anything i can do to speed this up? perhapes i can just
implement a function equivalent to gethostbyname using fsockopen, or
something?

any help would be appreciated - thanks!

Jul 17 '05 #1
5 6012
On 6 Mar 2005 15:46:05 -0800, "yawnmoth" <te*******@yahoo.com> wrote:
using the gethostbyname function seems to noticeably slow down pages.
some of the comments in php.net's gethostbyname entry suggest using a
version that caches the result, but those versions also only speedup
subsequent calls to gethostbyname - the first call is still as slow as
ever.

so is there anything i can do to speed this up?
Are lookups slow from the commandline using 'host' or 'nslookup'? How slow is
slow? It's unavoidable that it'll take some time.
perhapes i can just
implement a function equivalent to gethostbyname using fsockopen, or
something?


Reinventing the wheel is probably the very last thing you want to consider -
name resolution involves communicating with other servers, so if it's just that
communication that's slow then reinventing DNS resolution code isn't going to
help.

--
Andy Hassall / <an**@andyh.co.uk> / <http://www.andyh.co.uk>
<http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool
Jul 17 '05 #2

Andy Hassall wrote:
On 6 Mar 2005 15:46:05 -0800, "yawnmoth" <te*******@yahoo.com> wrote:
using the gethostbyname function seems to noticeably slow down pages.some of the comments in php.net's gethostbyname entry suggest using aversion that caches the result, but those versions also only speedup
subsequent calls to gethostbyname - the first call is still as slow asever.

so is there anything i can do to speed this up?
Are lookups slow from the commandline using 'host' or 'nslookup'?

How slow is slow? It's unavoidable that it'll take some time.


Lookups performed from the command line take 0 seconds, whereas lookups
performed with gethostbyname take 5 seconds. here's the php script i
used to determine this:

<?
$start = time();
echo `host google.com`.'(took '.(time()-$start).' seconds)<br>';

$start = time();
echo gethostbyname('google.com').' (took '.(time()-$start).'
seconds)';
?>

Jul 17 '05 #3
yawnmoth wrote:
Andy Hassall wrote:
On 6 Mar 2005 15:46:05 -0800, "yawnmoth" <te*******@yahoo.com> wrote:
using the gethostbyname function seems to noticeably slow down
pages. some of the comments in php.net's gethostbyname entry
suggest using a version that caches the result, but those versions
also only speedup subsequent calls to gethostbyname - the first
call is still as slow as ever.

so is there anything i can do to speed this up?


Are lookups slow from the commandline using 'host' or 'nslookup'?
How slow is slow? It's unavoidable that it'll take some time.


Lookups performed from the command line take 0 seconds, whereas
lookups performed with gethostbyname take 5 seconds. here's the php
script i used to determine this:

<?
$start = time();
echo `host google.com`.'(took '.(time()-$start).' seconds)<br>';

$start = time();
echo gethostbyname('google.com').' (took '.(time()-$start).'
seconds)';


My results running that script are:
google.com has address 216.239.39.99 google.com has address 216.239.57.99
google.com has address 216.239.37.99 (took 0 seconds)
216.239.57.99 (took 0 seconds)

which definitely does *not* reflect a 5 second execution time.

--
Virgil
Jul 17 '05 #4

Virgil Green wrote:
yawnmoth wrote:
Andy Hassall wrote:
On 6 Mar 2005 15:46:05 -0800, "yawnmoth" <te*******@yahoo.com> wrote:
<snip>
Lookups performed from the command line take 0 seconds, whereas
lookups performed with gethostbyname take 5 seconds. here's the php script i used to determine this:

<?
$start = time();
echo `host google.com`.'(took '.(time()-$start).' seconds)<br>';

$start = time();
echo gethostbyname('google.com').' (took '.(time()-$start).'
seconds)';


My results running that script are:
google.com has address 216.239.39.99 google.com has address

216.239.57.99 google.com has address 216.239.37.99 (took 0 seconds)
216.239.57.99 (took 0 seconds)

which definitely does *not* reflect a 5 second execution time.


I guess it's a problem with my server configuation, or something...

Any ideas as to what, specifically, is the problem? I haven't any...

Jul 17 '05 #5
TerraFrost wrote:
Virgil Green wrote:
yawnmoth wrote:
Andy Hassall wrote:
On 6 Mar 2005 15:46:05 -0800, "yawnmoth" <te*******@yahoo.com>
wrote:

<snip>

Lookups performed from the command line take 0 seconds, whereas
lookups performed with gethostbyname take 5 seconds. here's the php
script i used to determine this:

<?
$start = time();
echo `host google.com`.'(took '.(time()-$start).' seconds)<br>';

$start = time();
echo gethostbyname('google.com').' (took '.(time()-$start).'
seconds)';


My results running that script are:
google.com has address 216.239.39.99 google.com has address
216.239.57.99 google.com has address 216.239.37.99 (took 0 seconds)
216.239.57.99 (took 0 seconds)

which definitely does *not* reflect a 5 second execution time.


I guess it's a problem with my server configuation, or something...

Any ideas as to what, specifically, is the problem? I haven't any...


Nope. I wouldn't even try to diagnose someone's network problems like this
on a remote basis. I don't know enough to solve the problem in the abstract.
By the way, you can run the code on my server using
http://www.obsydian.com/gethostbyname.php

--
Virgil
Jul 17 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Fortepianissimo | last post: by
5 posts views Thread by ruroma | last post: by
1 post views Thread by Glen Conway | last post: by
1 post views Thread by Quentin Carbonneaux | last post: by
reply views Thread by Ryan Liu | last post: by
1 post views Thread by yawnmoth | last post: by
2 posts views Thread by Andrew DeFaria | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.