From: andrew at neonsurge dot com
Operating system: Gentoo, OS-X 10.4
PHP version: 5.2.1
PHP Bug Type: Streams related
Bug description: fsockopen() always forces a DNS resolution unnecessarily
Description:
------------
fsockopen() always asks your DNS server for the IP address
of a connection before it opens it, instead of trying to
look in the local cache first. I believe this is unexpected
and performance-wise is a very undesirable operation. See
reproduce code...
Reproduce code:
---------------
<?php for ($i = 0; $i < 50; $i++) {
$errno = $errstr = "";
//$ip = gethostbyname("php.net"); $a =
fsockopen($ip,22,$errno,$errstr,10); //FAST way
$a = fsockopen("php.net",22,$errno,$errstr,10); //SLOW way
$ab = fread($a,4096); unset($a, $ab);
} ?>
Expected result:
----------------
While running the slower code above exactly as
is, you can packet sniff and view 50 full requests for the
domain php.net. This is unoptimized and causes this code to
run extremely slow.
When running with the fast way (change lines commented out)
the above code runs a few hundred percent faster. Upon a
packet sniff you can watch 1 or two requests for php.net
being sent to your DNS server which I believe is the desired
result.
NOTE: In the code above I do have the workaround by
connecting with the IP instead by using gethostbyname()
first which appears to use the local DNS cache.
Actual result:
--------------
The code above should run exactly the same speed either way.
fsockopen should be using the local machine's DNS cache and
not have to query the DNS server upon every request when
given a DNS name to connect to.
--
Edit bug report at http://bugs.php.net/?id=40427&edit=1
--
Try a CVS snapshot (PHP 4.4):
http://bugs.php.net/fix.php?id=40427&r=trysnapshot44
Try a CVS snapshot (PHP 5.2):
http://bugs.php.net/fix.php?id=40427&r=trysnapshot52
Try a CVS snapshot (PHP 6.0):
http://bugs.php.net/fix.php?id=40427&r=trysnapshot60
Fixed in CVS: http://bugs.php.net/fix.php?id=40427&r=fixedcvs
Fixed in release:
http://bugs.php.net/fix.php?id=40427&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=40427&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=40427&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=40427&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=40427&r=support
Expected behavior: http://bugs.php.net/fix.php?id=40427&r=notwrong
Not enough info:
http://bugs.php.net/fix.php?id=40427&r=notenoughinfo
Submitted twice:
http://bugs.php.net/fix.php?id=40427&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=40427&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=40427&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=40427&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=40427&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=40427&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=40427&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=40427&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=40427&r=mysqlcfg