System: Drupal 4.6.2 running on Windows 2003 IIS. with PHP 5.0.4

Download from filestore2/FSCache fails.
When downloading from the filestore2 block (Block Top 5 Files)
the download simply stops just before 2Mbyte.

Searching google say something about readfile() bug in PHP 5.0.4

Upload is OK, files larger than 2M byte is saved so it is not a php.ini problem.

Did not find any limitation in the settings.php or anywhere else.

Roger over and out

Niel

Comments

gordon’s picture

maybe try increasing the max_execution_time this maybe what the problem is. Also can you please post the link to the 5.0.4 problem as it may have a method of getting around this.

niel-1’s picture

Somehow it's not a timeout problem. Slow or fast links produce the same result.
The file stops downloading when the download size is over 1Mbyte and under 2Mbyte.
(The result is different every time)

Direct download (without FSCache) is no problem...

Any good idears?

m3avrck’s picture

Version: 4.6.x-1.x-dev » master

Yes this is a problem with PHP5, here is the work around code:

/* 
   i found out that there is already a disscussion @php-dev  about 
   readfile() and fpassthru() where only exactly 2 MB will be delivered.
   so you may use this on php5 to get lager files 
*/
function readfile_chunked($filename,$retbytes=true) {
   $chunksize = 1*(1024*1024); // how many bytes per chunk
   $buffer = '';
   $cnt =0;
   // $handle = fopen($filename, 'rb');
   $handle = fopen($filename, 'rb');
   if ($handle === false) {
       return false;
   }
   while (!feof($handle)) {
       $buffer = fread($handle, $chunksize);
       echo $buffer;
       if ($retbytes) {
           $cnt += strlen($buffer);
       }
   }
       $status = fclose($handle);
   if ($retbytes && $status) {
       return $cnt; // return num. bytes delivered like readfile() does.
   }
   return $status;
} 

Link reference: http://bugs.php.net/bug.php?id=32970

Appears to be fixed in CVS, but can't determine if this is 5.0.5 or 5.1.

m3avrck’s picture

Priority: Critical » Normal
Status: Active » Closed (fixed)

Just confirmed this with a main PHP developer, this bug is indeed fixed in 5.0.5 and the 5.1. As such, this problem only occurs for users who are using PHP 5.0 to 5.0.4 and I would suggest upgrading. This bug is now closed.

niel-1’s picture

Thank's the patch works great with 5.0.4