From: wckits at rit dot edu Operating system: SunOS 5.9 PHP version: 5.0.5 PHP Bug Type: Sockets related Bug description: stream_set_timeout has no effect on SSL stream
Description: ------------ A stream opened with stream_socket_client("ssl://..... will not timeout when reading. This may have a similar underlying cause to bug #23618 but it is exposed differently, and is still a problem in 5.0.5. Reproduce code: --------------- #!/bin/php-5.0.5/sapi/cli/php <? //First connect and do something to prove that we are properly connected. print "Setting up context\n"; $ctx = stream_context_create(array( 'ssl'=>array( 'verify_peer' => false, 'allow_self_signed' => true, ) )); print "Creating socket\n"; $socket = stream_socket_client( "ssl://www.rit.edu:443", &$errno, &$errstr, 10, STREAM_CLIENT_CONNECT, $ctx ); print "Setting timeout\n"; var_dump(stream_set_timeout( $socket, 5 )); print "Sending bogus request\n"; fwrite($socket, "GET nourl Cupcakes/2.5\n\n\n\n" ); print "Reading Result\n"; var_dump(fgets( $socket)); //Now conenct and read when we know the server isnt going to send anything print "Creating NEW socket\n"; $socket = stream_socket_client( "ssl://www.rit.edu:443", &$errno, &$errstr, 10, STREAM_CLIENT_CONNECT, $ctx ); print "Setting timeout\n"; var_dump(stream_set_timeout( $socket, 5 )); print "Sending NO request\n"; print "Read should time out in 5....\n"; var_dump(fgets( $socket)); ?> Expected result: ---------------- The first section will run and print an HTTP error. The second section will run and timeout after printing "Read should timeout in 5..." Actual result: -------------- Read does not time out. I suspect that the read timeout on SSL connections is just not implemented, because it is hard, but if that is the case the stream_set_timeout should return false to indicate the error. If its just not implemented I'd be willing to patch it up if there is one place to fix it. If there are ssl reads all over the php source I don't think I'd have the time to track them all down. I have seen people say "just use select" in response to stream timeout problems. That does not work with ssl, or at least it may not always work with ssl. Select can be used if you have access to the native SSL interface (ie: it could be done right in C) but you need to be able to check for the WANT_READ condition.... -- Edit bug report at http://bugs.php.net/?id=35105&edit=1 -- Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=35105&r=trysnapshot4 Try a CVS snapshot (php5.0): http://bugs.php.net/fix.php?id=35105&r=trysnapshot50 Try a CVS snapshot (php5.1): http://bugs.php.net/fix.php?id=35105&r=trysnapshot51 Fixed in CVS: http://bugs.php.net/fix.php?id=35105&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=35105&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=35105&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=35105&r=needscript Try newer version: http://bugs.php.net/fix.php?id=35105&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=35105&r=support Expected behavior: http://bugs.php.net/fix.php?id=35105&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=35105&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=35105&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=35105&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=35105&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=35105&r=dst IIS Stability: http://bugs.php.net/fix.php?id=35105&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=35105&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=35105&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=35105&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=35105&r=mysqlcfg