From: nalldrin at cs dot ucsd dot edu
Operating system: Windows XP Pro
PHP version: 4.3.2
PHP Bug Type: Sockets related
Bug description: fsockopen not detecting closed ports
Description:
------------
I'm running PHP 4.3.2 on Windows XP and think I've found a bug in
fsockopen(). When attempting to open a closed, non-blocked port,
fsockopen() times out instead of returning immediately. On linux,
fsockopen() returns immediately instead of timing out. I've tried the
latest CVS version (php4-win32-STABLE-200307211230) and get the same
problem. Also perhaps relevant is the fact that fopen() seems to work
correctly (ie, it does not time out like fsockopen).
Note: I think this is the same problem as bugs 23131, 21193, etc., but the
problem does not seem to be fixed.
Here's some more info about the machine/php version I'm running:
System:
Microsoft Windows XP Professional Version 2002 Service Pack 1
Xeon 3.06GHz
512MB RAM
PHP:
<a href="http://louis.ucsd.edu/~nalldrin/phpbug/phpinfo.html>phpinfo</a>
Reproduce code:
---------------
<?php
set_time_limit(0);
$hostname = 'localhost'; //use any hostname:port combo that is closed, but
not blocked
$port = 81;
$errno = null;
$error_str = null;
// FSOCKOPEN does not detect closed port and waits until timeout
echo microtime() . "\n";
$fp = fsockopen( $hostname, $port, $errno, $error_str, 10);
echo microtime();
echo "\nerrno: "; var_dump($errno);
echo "error_str: "; var_dump($error_str);
echo "retval: "; var_dump($fp);
if ($fp !== false) fclose($fp);
// FOPEN seems to correctly detect closed port and returns immediately
echo microtime() . "\n";
$fp2 = fopen ("http://$hostname:$port",
"r");
echo microtime();
if ($fp2 !== false) fclose($fp2);
?>
Expected result:
----------------
The script should return immediately, saying the hostname/port is closed
or something to that effect.
Actual result:
--------------
The fsockopen() call times out.
..........................................
0.98491200 1058903395
<br />
<b>Warning</b>: fsockopen(): php_hostconnect: connect failed in
<b>c:\Inetpub\wwwroot\phpbug\fsockopenbug.php</b> on line <b>11</b><br
/>
<br />
<b>Warning</b>: fsockopen(): unable to connect to localhost:81 in
<b>c:\Inetpub\wwwroot\phpbug\fsockopenbug.php</b> on line <b>11</b><br
/>
0.98788000 1058903405
errno: int(10060)
error_str: string(185) "A connection attempt failed because the connected
party did not properly respond after a period of time, or established
connection failed because connected host has failed to respond."
retval: bool(false)
0.98791200 1058903405
<br />
<b>Warning</b>: fopen(): php_hostconnect: connect failed in
<b>c:\Inetpub\wwwroot\phpbug\fsockopenbug.php</b> on line <b>22</b><br
/>
<br />
<b>Warning</b>: fopen(http://localhost:81): failed to open stream: Bad
file descriptor in <b>c:\Inetpub\wwwroot\phpbug\fsockopenbug.php</b> on
line <b>22</b><br />
0.94688200 1058903406
--
Edit bug report at http://bugs.php.net/?id=24756&edit=1
--
Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=24756&r=trysnapshot4
Try a CVS snapshot (php5): http://bugs.php.net/fix.php?id=24756&r=trysnapshot5
Fixed in CVS: http://bugs.php.net/fix.php?id=24756&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=24756&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=24756&r=needtrace
Try newer version: http://bugs.php.net/fix.php?id=24756&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=24756&r=support
Expected behavior: http://bugs.php.net/fix.php?id=24756&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=24756&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=24756&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=24756&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=24756&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=24756&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=24756&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=24756&r=gnused