I'm back with good news
My theory above was correct. I've tested it with 700mb file. With default 4images the whole 700mb were loaded into the memory (I was monitoring it with linux "top" command).
After implimenting my code, the memory usage didnt move from normal, and file was successfuly downloaded, and also, the download dialog window poped up instantly, without 10 seconds delay as with default code
Before we begin, please note, that zip type downloads and remote files are not supported by these changes, in fact, remote files download might not work any longer (I did not test it)
Open download.php
1) Find:
function get_file_data($file_path) {
Replace with:
function get_file_data($file_path, $size = 0) {
if ($size)
{
if (!file_exists($file_path) || !$size = filesize($file_path)) return false;
return $size;
}
2) Find:
elseif (!$file['file_data'] = get_file_data($file['file_path'])) {
Replace with:
elseif (!$file['file_size'] = get_file_data($file['file_path'], 1)) {
3) Find:
if ($action == "zip" && !eregi("\.zip$", $file['file_name']) && function_exists("gzcompress") && function_exists("crc32")) {
Insert
below:
$file['file_data'] = get_file_data($file['file_path']);
4) A few lines below find:
$file['file_size'] = strlen($file['file_data']);
Comment it out or simply remove that line.
Note that there are two instances of this line, you need the last instance. below that line should be
echo $lang['download_error']."\n<!-- EMPTY FILE PATH //-->";5) Find:
if (!empty($file['file_data'])) {
Comment it out or remove that line.
6) Find:
echo $file['file_data'];
Replace with:
if (!empty($file['file_data'])) {
echo $file['file_data'];
}
else
{
if ($handle = @fopen($file['file_path'], "rb"))
{
while (!feof($handle))
{
print fread($handle, 512000);
@ob_flush();
@flush();
}
fclose($handle);
}
That's it.
In last step number 512000 represent how many bytes the script will read at ones. (1 KB = 1024 B; 1024 * 500 = 512000 B = 500 KB) You might want to play with that value to find best perfomance.