Skip to content

Commit

Permalink
BUG Prevent PHP from eating all memory when serving large files.
Browse files Browse the repository at this point in the history
  • Loading branch information
mateusz committed Apr 2, 2014
1 parent 77045ad commit 7d6ddb2
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion code/SecureFileController.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,16 @@ public function sendFile($file) {
header('Content-Transfer-Encoding: binary');
header('Pragma: '); // Fixes IE6,7,8 file downloads over HTTPS bug (http://support.microsoft.com/kb/812935)

readfile($path);
// Allow the download to last long enough to allow full download with 100kB/s connection.
// Equates to 174 minutes per 1GB.
increase_time_limit_to(filesize($path)/(100*1024));

// Do not use readfile, it will try to post entire file in one go if output_buffering is enabled in php.ini.
$f = fopen($path, 'r');
while(!feof($f)){
print fgets($f, 4096);
}
fclose($f);
die();
}

Expand Down

0 comments on commit 7d6ddb2

Please sign in to comment.