#24756 [Ver->NoF]: fsockopen not detecting closed ports
ID: 24756
Updated by: iliaa@php.net
Reported By: nalldrin at cs dot ucsd dot edu
-Status: Verified
+Status: No Feedback
Bug Type: Sockets related
Operating System: Windows XP Pro
PHP Version: 4.3.3RC2-dev
New Comment:
Please try using this CVS snapshot:
http://snaps.php.net/php4-STABLE-latest.tar.gz
For Windows:
http://snaps.php.net/win32/php4-win32-STABLE-latest.zip
Previous Comments:
------------------------------------------------------------------------
[2003-07-24 09:08:07] iliaa@php.net
On WinXP using latest stable snapshot from July 24th does infact stall
and wait for the timeout to occur.
<?php
fsockopen("www.php.net", 9999, $errno, $err_str, 10);
?>.
However, this does not appear to happen with PHP5 snapshot.
------------------------------------------------------------------------
[2003-07-23 14:10:16] nalldrin at cs dot ucsd dot edu
Yes, that's what I mean.
I wrote a more simple test case that tries to open port 9999 on
www.php.net. On linux the test returns immediately, as it should. But
on win32, it spins until timeout.
..............................
<?php
// fsockopen spins on win32 on opening non-existant ports when it
should fail
immediately.
$startTime = time();
fsockopen("www.php.net", 9999, $errno, $error_str, 10);
$totalTime = time() - $startTime;
if($totalTime >= 10) {
print("Spun until timeout trying to open a closed port. Huh?");
}
?>
..............................
Output:
..............................
Content-type: text/html
X-Powered-By: PHP/4.3.2
<br />
<b>Warning</b>: fsockopen(): php_hostconnect: connect failed in
<b>C:\cygwin\home\Neil Alldrin\test.php</b> on line <b>7</b><br />
<br />
<b>Warning</b>: fsockopen(): unable to connect to www.php.net:9999 in
<b>C:\cygwin\home\Neil Alldrin\test.php</b> on line <b>7</b><br />
Spun until timeout trying to open a closed port. Huh?
------------------------------------------------------------------------
[2003-07-23 01:10:06] wez@php.net
*sigh* yes, fsockopen() creates a tcp connection.
the http:// wrapper uses those tcp connections to talk http.
So... you just mean a port that is not filtered but has no processes
listening on it?
--Wez.
------------------------------------------------------------------------
[2003-07-23 01:06:44] nalldrin at cs dot ucsd dot edu
The problem isn't with fopen(); it's with fsockopen() which should be
trying to create a raw tcp:// connection, not an http:// connection.
The point of comparing fsockopen with fopen was to show that somehow
fopen can tell that the port is closed while fsockopen cannot (since
they both need a tcp:// connection).
What I mean by "closed but not blocked" is a port that won't accept a
tcp connection, but still sends out a reply to the connection attempt
saying it's closed. A blocked port would pretend it didn't see the
connection attempt at all. I'm probably muddling my terminology, but
that's what I mean :).
------------------------------------------------------------------------
[2003-07-23 00:54:48] wez@php.net
The http:// wrapper internally calls the same connection routines as
fsockopen, so I can't see how it could be behaving differently (error
messages aside).
Can you explain what you mean by a closed-but-not-blocked port?
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
http://bugs.php.net/24756
--
Edit this bug report at http://bugs.php.net/?id=24756&edit=1
Thread (9 messages)