PHP readfile() and large downloads
- by Nirmal
While setting up an online file management system, and now I have hit a block.
I am trying to push the file to the client using this modified version of readfile:
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; 
       ob_flush(); 
       flush(); 
       if ($retbytes) { 
           $cnt += strlen($buffer); 
       } 
   } 
       $status = fclose($handle); 
   if ($retbytes && $status) { 
       return $cnt; // return num. bytes delivered like readfile() does. 
   } 
   return $status; 
}
But when I try to download a 13 MB file, it's just breaking at 4 MB.
What would be the issue here? It's definitely not the time limit of any kind because I am working on a local network and speed is not an issue.
The memory limit in PHP is set to 300 MB.
Thank you for any help.