|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #32810 fread after tmpfile() reads only 8192 bytes
Submitted: 2005-04-24 16:04 UTC Modified: 2005-05-23 23:52 UTC
From: matteo at beccati dot com Assigned: tony2001 (profile)
Status: Closed Package: Filesystem function related
PHP Version: 5CVS, 4CVS (2005-04-24) OS: *
Private report: No CVE-ID: None
 [2005-04-24 16:04 UTC] matteo at beccati dot com
In recent PHP versions, fread only reads 8192 bytes from a file generated with tmpfile().

I've already seen bug reports #29023 and #30936 which seem strongly related to this issue. From what I can see, fread on local files isn't limited to the PHP chunk size of 8192, while a fread on a tmpfile acts like it was i.e. a network stream, breaking backwards compatibility. I found out this issue investigating a recently reported bug for phpAdsNew, which uses this function to deal with remote ftp-stored files.

IMVHO this can be considered a bug in in the tmpfile() implementation. If you don't agree, well... I suggest to mark it as a documentation bug, because I couldn't find nothing related to the 8192 bytes limit in the manual.

Versions/OS tested and affected:
PHP 4.3.10 Linux
PHP 4.3.11 FreeBSD and Windows
PHP 5.0.4  Windows

Versions/OS tested and unaffected:
PHP 4.3.4  Windows

Reproduce code:

$fp = tmpfile();  

// This would give the correct result
// $fp = fopen('/tmp/test.dat', 'w+');

fwrite($fp, str_repeat('0', 100000));

$size = ftell($fp);
$buf = fread($fp, $size);

echo "Bytes written: ".$size."\n";
echo "Bytes read:    ".strlen($buf)."\n";



Expected result:
Bytes written: 100000
Bytes read:    100000

Actual result:
Bytes written: 100000
Bytes read:    8192


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2005-04-24 16:40 UTC]
Wez breaks, Wez fixes. (Streams stuff broke this)

 [2005-05-22 00:32 UTC]
php5-win32-200505191430 is still suffering from this.
 [2005-05-23 23:52 UTC]
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
Thank you for the report, and for helping us make PHP better.

PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Tue Nov 28 17:01:27 2023 UTC