By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,908 Members | 2,055 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,908 IT Pros & Developers. It's quick & easy.

gethostbyname slow

P: n/a
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
Share this Question
Share on Google+
5 Replies


P: n/a
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

P: n/a

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

P: n/a
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

P: n/a

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

P: n/a
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.