#37158 [Opn->Bgs]: if userspace stream is present, fread() reads in 8192 max, otherwise it works
| From: | pajoye@php.net | Date: | Fri, 21 Apr 2006 22:40:10 +0000 |
| Subject: | #37158 [Opn->Bgs]: if userspace stream is present, fread() reads in 8192 max, otherwise it works | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-96080@lists.php.net to get a copy of this message | ||
ID: 37158
Updated by: pajoye@php.net
Reported By: cellog@php.net
-Status: Open
+Status: Bogus
Bug Type: Streams related
Operating System: n/a
PHP Version: 5CVS-2006-04-21 (CVS)
New Comment:
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php
"...or (after opening userspace stream) when 8192 bytes have been read
whichever comes first."
I think it is clear. What do you suggest to make it more clear? Reopen
and change it to "documentation" bug if you have a better text.
It is not a bug.
Previous Comments:
------------------------------------------------------------------------
[2006-04-21 22:15:15] cellog@php.net
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()
------------------------------------------------------------------------
[2006-04-21 22:11:09] cellog@php.net
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