|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #31350 Max reading length of STDIN is 8192bytes
Submitted: 2004-12-30 11:59 UTC Modified: 2004-12-31 01:21 UTC
Avg. Score:4.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: gibspam at carnation dot hu Assigned:
Status: Not a bug Package: Filesystem function related
PHP Version: 4.3.10 OS: Redhat Linux 7.1-7.3
Private report: No CVE-ID: None
 [2004-12-30 11:59 UTC] gibspam at carnation dot hu
I write a script which reads a file from STDIN, and writes it out the content of it to a new file. It worked fine with php 4.3.4, but when I upgraded to any newer version, then it failed to read the whole file from stdin. I expected to read the file into a 128000 bytes buffer but it reads only 8192 bytes instead of 128000 bytes.

Reproduce code:
$file_length = 6596594;

if (!$fp = fopen("","w"))
		die("file open error");

$count =  (($file_length / UPLOAD_BUFFER));
echo "\nmax i should be: ".$count;
for ($i = 1; $i < $count; $i ++) {
	$str = fread(STDIN, UPLOAD_BUFFER);
	echo "\ni: ".$i." length:".strlen($str);
	fwrite($fp, $str);

$remainder = $file_length % UPLOAD_BUFFER;

if (0 != $remainder) {
	$str = fread(STDIN, $remainder);
	echo "\nlast length:".strlen($str);
	fwrite($fp, fread(STDIN, $remainder));


Expected result:
If I run my script with this command:
php -q ./my.php < file_with_size_of_6596594_bytes.bin

I expect to get a new file created (, with the same content as the file_with_size_of_6596594_bytes.bin.

Actual result:
As a result a new file created (, which is 425984 bytes long.


But, it shuld be



Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2004-12-31 01:21 UTC]
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at and the instructions on how to report
a bug at

PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Mon Nov 30 14:01:24 2020 UTC