PHP Bugs  
php.net | support | documentation | report a bug | advanced search | search howto | statistics | login

go to bug id or search bugs for  

Bug #35859 fread limited to 8K
Submitted:31 Dec 2005 2:20pm UTC Modified: 26 Feb 2006 7:00pm UTC
From:cpuidle at gmx dot de Assigned to:
Status:Closed Category:Documentation problem
Version:5.1.1 OS:WinXP SP2
View/Vote Developer Edit Submission

[31 Dec 2005 2:20pm UTC] cpuidle at gmx dot de
Description:
------------
I'm experiencing a very weird bug where fread is limited to 8K though
the source file (ANSI) is bigger than 8K. I was not able to reproduce
the bug standalone, only inside a complex application.

This does not happen with PHP5.0.5, but with 5.1.1.

Unfortunately the sample code does not reproduce the problem standalone,
but demonstrates the effect.

Reproduce code:
---------------
function _read_file($filename)
{
if ( file_exists($filename) && ($fd = @fopen($filename, 'rb')) ) {
    $contents = ($size = filesize($filename)) ? fread($fd, $size) : '';
    echo("_read_file($filename) \$size: $size strlen(\$contents):
".strlen($contents)."<br/>");
    fclose($fd);
}
}

_read_file('templates/elegant/\show.tpl');

Expected result:
----------------
Output:
_read_file(templates/elegant/\show.tpl) $size: 9520 strlen($contents):
9520

Actual result:
--------------
Output:
_read_file(templates/elegant/\show.tpl) $size: 9520 strlen($contents):
8192
[6 Jan 2006 4:50pm UTC] sniper@php.net
reclassified (see bug #30936 for Wez's comment)
[6 Jan 2006 4:55pm UTC] cpuidle at gmx dot de
OK, at least a documentation problem, thanks. The dependency on stread
wrappers still seem to be a non-docs bug to me. And the sudden change in
behaviour certainly doesn't help with the often-claimed enterprise
readiness...
Why should existing 5.0.5 code suddenly break with 5.1.1?
[13 Jan 2006 12:00pm UTC] vrana@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation
better.

"Reading stops when up to length bytes have been read, EOF (end of file)
is reached, (for network streams) when a packet becomes available, or
(for userspace streams) when 8192 bytes have been read whichever comes
first."
[16 Jan 2006 9:19am UTC] cpuidle at gmx dot de
Sorry, but the documentation is still wrong- did anybody ever look at
the code to reproduce?!

"or (for userspace streams) when 8192 bytes have been read whichever
comes
first."

When stream wrappers are not used (even unrelated protocols count as
stream wrapper use), the 8K limit is not in effect. 

So- documentation wrong again...
[30 Jan 2006 4:48pm UTC] vrana@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation
better.

"(for userspace streams)" changed to "(after opening userspace stream)".
[26 Feb 2006 7:00pm UTC] cpuidle at gmx dot de
Now to summarize what happened:

1) For local files, PHP behaved exactly like documented until version
5.1.0
2) When 5.1.1 was introduced, local file behaviour for fread() changed
to limit to 8K blocks- however if and only if a user stream was opened
before
3) In response to this, the documentation was changed to accomodate for
the user stream behaviour.

What I'm asking the PHP developers community to ask them selves very
seriously is this:

a) won't this break compatibility with many existing software as PHP5
becomes more widely spread (Smarty etc)?
b) isn't the bahviour change of fread depending on other criteria itself
a strangeness? and
c) looking at this issue- is PHP in any way enterprise-ready?

Sincerely,
Andreas Goetz

RSS feed | show source 

PHP Copyright © 2001-2009 The PHP Group
All rights reserved.
Last updated: Sat Nov 21 10:30:49 2009 UTC