#30734 [NEW]: stream_get_meta_data does not return the correct number of unread bytes

From: Date: Tue, 09 Nov 2004 14:52:44 +0000
Subject: #30734 [NEW]: stream_get_meta_data does not return the correct number of unread bytes
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-68849@lists.php.net to get a copy of this message
From: kormoc at gmail dot com Operating system: Linux PHP version: 5.0.2 PHP Bug Type: Sockets related Bug description: stream_get_meta_data does not return the correct number of unread bytes Description: ------------ For a stream in blocking or non blocking mode, stream_get_meta_data does not return the correct number of unread bytes until it's been 'freshened' by a fread or similar. For example, the test program. The unread bytes will be 0, but if you insert a fgets($fp) above the stream_get_meta_data line, it will return the correct number of bytes. It also does this if blocking is set to false. If you need any more information about my setup, feel free to ask, it's really not that odd or special. Thanks! Reproduce code: --------------- <?PHP $fp=fsockopen("irc.freenode.net",6667); stream_set_blocking($fp,TRUE); fwrite($fp,"NICK BOOT\nUSER BOOT 0 * :BOOT\n\n"); $read=array($fp); while(1) { if(false===($num_changed_streams=stream_select($read,$write=NULL,$except=NULL,1))) break; else { $data=stream_get_meta_data($fp); print_r($data); while($data['unread_bytes']>0) { echo fgets($fp); $data=stream_get_meta_data($fp); } } } fclose($fp); ?> Expected result: ---------------- Something similar to this kormoc@kormoc ~ $ php streamtest.php NOTICE AUTH :*** Looking up your hostname... Array ( [stream_type] => tcp_socket/ssl [mode] => r+ [unread_bytes] => 0 [seekable] => [timed_out] => [blocked] => 1 [eof] => ) NOTICE AUTH :*** Found your hostname, welcome back Array ( [stream_type] => tcp_socket/ssl [mode] => r+ [unread_bytes] => 77 [seekable] => [timed_out] => [blocked] => 1 [eof] => ) NOTICE AUTH :*** Checking ident NOTICE AUTH :*** No identd (auth) response :sendak.freenode.net 432 BOOT :Erroneous Nickname Array ( [stream_type] => tcp_socket/ssl [mode] => r+ [unread_bytes] => 0 [seekable] => [timed_out] => [blocked] => 1 [eof] => ) Actual result: -------------- Array ( [stream_type] => tcp_socket/ssl [mode] => r+ [unread_bytes] => 0 [seekable] => [timed_out] => [blocked] => 1 [eof] => ) (repeating forever) -- Edit bug report at http://bugs.php.net/?id=30734&edit=1 -- Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=30734&r=trysnapshot4 Try a CVS snapshot (php5.0): http://bugs.php.net/fix.php?id=30734&r=trysnapshot50 Try a CVS snapshot (php5.1): http://bugs.php.net/fix.php?id=30734&r=trysnapshot51 Fixed in CVS: http://bugs.php.net/fix.php?id=30734&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=30734&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=30734&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=30734&r=needscript Try newer version: http://bugs.php.net/fix.php?id=30734&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=30734&r=support Expected behavior: http://bugs.php.net/fix.php?id=30734&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=30734&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=30734&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=30734&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=30734&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=30734&r=dst IIS Stability: http://bugs.php.net/fix.php?id=30734&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=30734&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=30734&r=float MySQL Configuration Error: http://bugs.php.net/fix.php?id=30734&r=mysqlcfg

« previous php.bugs (#68849) next »