From:             nicolas dot legland at free dot fr
Operating system: Windows XP Professional SP2
PHP version:      5.3CVS-2007-12-28 (snap)
PHP Bug Type:     Streams related
Bug description:  Asynchronous socket connection timing issue

Description:
------------
Asynchronously connecting a TCP socket stream to a filtered port times
out, but closing the resource using fclose() blocks for 0.5 second.

Asynchronously connecting a TCP socket stream to a closed port ends up
with the server explicitly refusing the connection by a RST ACK packet.
Using stream_select() returns the stream resource as having had an except
but trying to close the resource using fclose() blocks for 0.5 second too.

No network transfer was captured by Wireshark apart from the initial SYN
packet in either case. Using fclose() on a successfully asynchronously
connected TCP socket stream to an open port returns instantaneously.

If you don't explicitly fclose() the resources of failed connections, the
same 0.5 seconds lag appears at the end of the script execution for each
one. PHP probably cleanly frees resources at shutdown, but it can reach
several seconds when several sockets have failed.

When using non-blocking BSD socket with the sockets extension, no delay of
any kind is noticed.

Reproduce code:
---------------
<?php

        // Send a [SYN] packet to scanme.nmap.org:70
        $time = microtime(true);
        $resource =
stream_socket_client('tcp://'.gethostbyname('scanme.nmap.org').':70', $null
= null, $null, 0, STREAM_CLIENT_ASYNC_CONNECT | STREAM_CLIENT_CONNECT);
        stream_set_blocking($resource, 0);
        echo 'Open      '.number_format((microtime(true) - $time), 6).PHP_EOL;

        // Wait 3 seconds for a [SYN, ACK] packet
        $time = microtime(true);
        $read = $write = $except = array($resource);
        stream_select($read, $write, $except, 3);
        echo 'Wait      '.number_format((microtime(true) - $time), 6).' read
'.count($read).', write '.count($write).', except
'.count($except).PHP_EOL;

        // Cancel connection
        $time = microtime(true);
        fclose($resource);
        echo 'Close     '.number_format((microtime(true) - $time), 6).PHP_EOL;

?>

Expected result:
----------------
Open    0.010317
Wait    1.588449        read 0, write 0, except 1
Close   0.000099

Actual result:
--------------
Open    0.010002
Wait    1.547396        read 0, write 0, except 1
Close   0.510161

-- 
Edit bug report at http://bugs.php.net/?id=43695&edit=1
-- 
Try a CVS snapshot (PHP 4.4): 
http://bugs.php.net/fix.php?id=43695&r=trysnapshot44
Try a CVS snapshot (PHP 5.2): 
http://bugs.php.net/fix.php?id=43695&r=trysnapshot52
Try a CVS snapshot (PHP 5.3): 
http://bugs.php.net/fix.php?id=43695&r=trysnapshot53
Try a CVS snapshot (PHP 6.0): 
http://bugs.php.net/fix.php?id=43695&r=trysnapshot60
Fixed in CVS:                 http://bugs.php.net/fix.php?id=43695&r=fixedcvs
Fixed in release:             
http://bugs.php.net/fix.php?id=43695&r=alreadyfixed
Need backtrace:               http://bugs.php.net/fix.php?id=43695&r=needtrace
Need Reproduce Script:        http://bugs.php.net/fix.php?id=43695&r=needscript
Try newer version:            http://bugs.php.net/fix.php?id=43695&r=oldversion
Not developer issue:          http://bugs.php.net/fix.php?id=43695&r=support
Expected behavior:            http://bugs.php.net/fix.php?id=43695&r=notwrong
Not enough info:              
http://bugs.php.net/fix.php?id=43695&r=notenoughinfo
Submitted twice:              
http://bugs.php.net/fix.php?id=43695&r=submittedtwice
register_globals:             http://bugs.php.net/fix.php?id=43695&r=globals
PHP 3 support discontinued:   http://bugs.php.net/fix.php?id=43695&r=php3
Daylight Savings:             http://bugs.php.net/fix.php?id=43695&r=dst
IIS Stability:                http://bugs.php.net/fix.php?id=43695&r=isapi
Install GNU Sed:              http://bugs.php.net/fix.php?id=43695&r=gnused
Floating point limitations:   http://bugs.php.net/fix.php?id=43695&r=float
No Zend Extensions:           http://bugs.php.net/fix.php?id=43695&r=nozend
MySQL Configuration Error:    http://bugs.php.net/fix.php?id=43695&r=mysqlcfg

Reply via email to