The current code in this component is limited when downloading large files (over 20mb).
Many servers are using the PHP memory limit set to aprox 15 to 25 mb which effectively limits the size of the download.
The current code using "readfile" will load all of the file into memory vs say "readfile_chunked" which passes only the chunk size into memory and then flushes the memory to load another chunk.
Currently the Virtuemart native download code uses this method. Also what ever Docman is using is also working to avoid this download limitation.
| Code: |
<?php
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;
}
?>
|
I have had to use an htaccess hack as a workaround for this code limitation. My issue is that using the hack works for one or two downloads BUT, given 30 to 50 downloads at the same time will cause a memory problen in PHP. This is why the PHP memory limit is in place...to protect it from scripts using all its memory up and therefore disabling its normal operation.
Please take this as a suggestion for your next version to make this code compatible both with the Virtuemart downlaod code and also as a great stand alone component.
Thank-you for your support...
Rick