From: aragon at phat dot za dot net Operating system: FreeBSD 7.0-STABLE PHP version: 5.2.7RC4 PHP Bug Type: Streams related Bug description: feof() blocking on non-blocking socket
Description: ------------ There was a change since 5.2.6 release that is causing feof() to block when testing a non-blocking socket for EOF. It happens if the socket has no data waiting in its buffer and is open. If I compare 5.2.6 and 5.2.7 code it looks like main/streams/streams.c:642: if (!stream->eof && PHP_STREAM_OPTION_RETURN_ERR == php_stream_set_option(stream, PHP_STREAM_OPTION_CHECK_LIVENESS, -1, NULL)) { stream->eof = 1; } In 5.2.6 php_stream_set_option is called with a value of 0, not -1. Reproduce code: --------------- <? $errno = 0; $errstr = ''; $socket = stream_socket_client('tcp://127.0.0.1:80', $errno, $errstr, 5, STREAM_CLIENT_CONNECT|STREAM_CLIENT_ASYNC_CONNECT); if (stream_set_blocking($socket, 0) === false) die('blah'); $state = $i = 1; while (1) { $read = $write = $except = null; switch ($state) { case 1: $write = array($socket); break; case 2: $read = array($socket); break; } echo $i.':'.time().chr(10); if (stream_select($read, $write, $except, 0, 500000) > 0) { echo $i.':'.time().chr(10); if (feof($socket)) break; echo $i++.':'.time().chr(10); switch ($state) { case 1: fwrite($socket, 'GET /blog HTTP/1.0' . chr(13).chr(10).chr(13).chr(10)); $state = 2; break; case 2: if (fread($socket, 8192)) echo 'ooo'.chr(10); break; } } } echo time().chr(10); ?> Expected result: ---------------- 1:0 1:0 1:0 2:0 2:0 2:0 ooo 3:0 3:0 0 Actual result: -------------- 1:0 1:0 1:5 2:5 2:5 2:5 ooo 3:5 3:5 5 -- Edit bug report at http://bugs.php.net/?id=46636&edit=1 -- Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=46636&r=trysnapshot52 Try a CVS snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=46636&r=trysnapshot53 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=46636&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=46636&r=fixedcvs Fixed in CVS and need be documented: http://bugs.php.net/fix.php?id=46636&r=needdocs Fixed in release: http://bugs.php.net/fix.php?id=46636&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=46636&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=46636&r=needscript Try newer version: http://bugs.php.net/fix.php?id=46636&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=46636&r=support Expected behavior: http://bugs.php.net/fix.php?id=46636&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=46636&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=46636&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=46636&r=globals PHP 4 support discontinued: http://bugs.php.net/fix.php?id=46636&r=php4 Daylight Savings: http://bugs.php.net/fix.php?id=46636&r=dst IIS Stability: http://bugs.php.net/fix.php?id=46636&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=46636&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=46636&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=46636&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=46636&r=mysqlcfg