From:             sysfly at gmail dot com
Operating system: Windows
PHP version:      5.3.14
Package:          Sockets related
Bug Type:         Bug
Bug description:socket_read non-blocking resets timeout with no data read

Description:
------------
If you call socket_read and it throws an error such as socket error 10035
then the 
connection will never timeout even if the remote side disconnects. Socket
error 
10035 is thrown if data is not ready to be read (hasn't been sent) yet and
is not 
really indicative of a disconnect or other fatal error.

Maybe there's a distinction to be made between fatal and nonfatal socket
errors. 
Possibly have it return an empty string instead of throwing a nonfatal
error? 
There is no data to read so that seems to be the more appropriate course of

action.

Test script:
---------------
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
$connected = socket_connect($socket, '127.0.0.1', 1337); // some server
that never sends you data. connection must be accepted though, or else this
throws an error.
socket_set_nonblock($socket);
socket_set_option($socket, SOL_SOCKET, SO_RCVTIMEO, array('sec' => 1,
'usec' => 0)); // set timeout to something fast, a second.

while (($read = @socket_read($socket, 1)) === false)
{
        // socket_read throwing an error doesn't mean the connection has failed
and the server is gone
        // in context, it just means the server hasn't sent any data yet. [in
testing, it never will.]
        if (socket_last_error($socket) != 10035)
                break; // an error that probably means we disconnected has been 
thrown!
}

echo('yay we did it! '.socket_last_error($socket));

Expected result:
----------------
yay we did it! (some FATAL error code)

Actual result:
--------------
infinite nothingness unless set_time_limit is set, in which case the
typical time 
limit exceeded error interrupts the script.

-- 
Edit bug report at https://bugs.php.net/bug.php?id=62394&edit=1
-- 
Try a snapshot (PHP 5.4):            
https://bugs.php.net/fix.php?id=62394&r=trysnapshot54
Try a snapshot (PHP 5.3):            
https://bugs.php.net/fix.php?id=62394&r=trysnapshot53
Try a snapshot (trunk):              
https://bugs.php.net/fix.php?id=62394&r=trysnapshottrunk
Fixed in SVN:                        
https://bugs.php.net/fix.php?id=62394&r=fixed
Fixed in SVN and need be documented: 
https://bugs.php.net/fix.php?id=62394&r=needdocs
Fixed in release:                    
https://bugs.php.net/fix.php?id=62394&r=alreadyfixed
Need backtrace:                      
https://bugs.php.net/fix.php?id=62394&r=needtrace
Need Reproduce Script:               
https://bugs.php.net/fix.php?id=62394&r=needscript
Try newer version:                   
https://bugs.php.net/fix.php?id=62394&r=oldversion
Not developer issue:                 
https://bugs.php.net/fix.php?id=62394&r=support
Expected behavior:                   
https://bugs.php.net/fix.php?id=62394&r=notwrong
Not enough info:                     
https://bugs.php.net/fix.php?id=62394&r=notenoughinfo
Submitted twice:                     
https://bugs.php.net/fix.php?id=62394&r=submittedtwice
register_globals:                    
https://bugs.php.net/fix.php?id=62394&r=globals
PHP 4 support discontinued:          
https://bugs.php.net/fix.php?id=62394&r=php4
Daylight Savings:                    https://bugs.php.net/fix.php?id=62394&r=dst
IIS Stability:                       
https://bugs.php.net/fix.php?id=62394&r=isapi
Install GNU Sed:                     
https://bugs.php.net/fix.php?id=62394&r=gnused
Floating point limitations:          
https://bugs.php.net/fix.php?id=62394&r=float
No Zend Extensions:                  
https://bugs.php.net/fix.php?id=62394&r=nozend
MySQL Configuration Error:           
https://bugs.php.net/fix.php?id=62394&r=mysqlcfg

Reply via email to