ID: 37158 Updated by: [EMAIL PROTECTED] Reported By: [EMAIL PROTECTED] Status: Open Bug Type: Streams related Operating System: n/a PHP Version: 5CVS-2006-04-21 (CVS) New Comment:
P.S. The documentation still sucks for fread() on the need to read in chunks. I ran into this bug because I had an fread() from a local file handle within a streams handler (pear.php.net/PHP_Archive) that had never been more than 8192 before. I would recommend fixing this by adding an E_STRICT warning if a value larger than 8192 is passed into fread() Previous Comments: ------------------------------------------------------------------------ [2006-04-21 22:11:09] [EMAIL PROTECTED] Description: ------------ fread($fp, 20000); will read in 20000 bytes from a local file, but is a userspace stream is defined anywhere, it will only read in 8192 bytes, without any warning or error. This is actually similar to Bug #30936, but as I say the problem here is that the presence of a userspace stream handler changes the behavior of fread() - any indeterminate behavior is bad. I wonder if the fix from #32810 could be helpful for this problem as well? Reproduce code: --------------- <?php // paste in the stream code from the example in the manual // be sure to include stream_wrapper_register error_reporting(E_ALL | E_STRICT); $file = dirname(__FILE__) . '/footest.txt'; $x = str_repeat('1', 8192); $fp = fopen($file, 'w'); for ($i = 0; $i < 5; $i++) { fwrite($fp, $x); } fclose($fp); $fp = fopen($file, 'r'); $outsidecontents = fread($fp, 20000); fclose($fp); var_dump('size of contents 1 = ' . strlen($outsidecontents)); $outsidecontents = file_get_contents($file); var_dump('size of contents 2 = ' . strlen($outsidecontents)); ?> Expected result: ---------------- string(26) "size of contents 1 = 20000" string(26) "size of contents 2 = 40960" Actual result: -------------- string(25) "size of contents 1 = 8192" string(26) "size of contents 2 = 40960" ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=37158&edit=1