php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #24001 fread limited by ca. 2.7K ?
Submitted: 2003-06-03 15:53 UTC Modified: 2003-07-07 21:43 UTC
From: eric at pitte dot de Assigned:
Status: Not a bug Package: Filesystem function related
PHP Version: 4.3.2 OS: Suse 8.2
Private report: No CVE-ID: None
 [2003-06-03 15:53 UTC] eric at pitte dot de
I'm using php4.3.2RC4 and Apache 2.0.45
using fopen / fread the reading stoped at constant 2.7KB whithout failure report . Here my script:
$Map="http://wwwserver.de/map.gif 
$karte = fopen ($Map, "rb");
$contents = fread ($karte, 1000000);
$sid = session_id();
$zeiger=fopen("temp/karte_${sid}.gif","wb");
fwrite($zeiger,$contents);
fclose($zeiger);
fclose($karte);

Any idee ?

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-06-03 15:55 UTC] derick@php.net
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

fread() uses the MAXIMUM length as you specify, but it may chunk the input as it likes.

Use something like:

$contents = \'\';
while (($data = fread($fp, 2048)) !== \"\") {
      $contents .= $data;
}
 [2003-06-03 16:06 UTC] eric at pitte dot de
yes it's working on this way. Thank you

strange on my older PHP version the old syntax worked properly.
 [2003-06-03 16:08 UTC] pollita@php.net
P.S. - To add to derick's response: 

The reason the file read is comming out specifically at 2.7KB is that the default chunksize for http streams is 4KB.  The "missing" 1.3KB is likely buried in the response headers.
 [2003-07-07 13:53 UTC] phpbug at digvid dot info
The documentation at http://uk.php.net/manual/en/function.fread.php states:

Reading stops when length bytes have been read or EOF (end of file) reached, whichever comes first.

This does not seem to be the case.

Ian
 [2003-07-07 14:26 UTC] wez@php.net
Also from the manual:

Note: When reading from network streams or pipes, such as those returned when reading remote files or from popen() and proc_open(), reading will stop after a packet is available. This means that you should collect the data together in chunks as shown in the example below. 

<?php
$handle = fopen ("http://www.php.net/", "rb");
$contents = "";
do {
    $data = fread ($handle, filesize ($filename));
    if (strlen($data) == 0) {
        break;
    }
    $contents .= $data;
}
fclose ($handle);
?>
 

 [2003-07-07 21:43 UTC] pollita@php.net
P.S. - About a week ago I expanded the opening note which phpbug@digvid.info quotes, however the manual has not been rebuilt yet.

    fread() reads up to length bytes from 
    the file pointer referenced by handle. 
    Reading stops when length bytes have 
    been read, EOF (end of file) is reached, 
    or (for network streams) when a packet 
    becomes available, whichever comes first. 

 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri May 03 21:01:32 2024 UTC