Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to start the download of remote big files directly?
    text
    copied!<p>I'm trying to pass a large file from an external API to the user, (think 100MB or more)</p> <p>Currently, I'm using a bit of a paranoid script (due to failures from the past) to get the script downloading ASAP.</p> <p>By 'downloading', I only mean the download trigger on the browser, not the actual downloading of the file. Just the point where user can select where (s)he wants to save the file.</p> <pre><code>set_time_limit(0); apache_setenv('no-gzip', 1); ini_set('zlib.output_compression', 0); ini_set('output_buffering', 0); ini_set('implicit_flush', 1); for($i = 0; $i &lt; ob_get_level(); $i++) { ob_end_flush(); } ob_implicit_flush(1); header('Content-Description: File Transfer'); header('Content-type: application/octet-stream'); header('Content-Transfer-Encoding: Binary'); header('Content-Disposition: attachment; filename="' . $filename . '"'); header('Cache-Control: private'); ob_flush(); flush(); $fh = fopen($external_api_url, 'rb'); while(!feof($fh)) { echo fread($fh, 512); ob_flush(); flush(); } fclose($fh); </code></pre> <p>Using this script, it still takes 20 seconds for a 50mb file before the download popup shows up, and much longer with bigger files.</p> <p>Is there any way to start the stream faster?</p> <p>EDIT: I've also tried fpassthru() and readfile() but these take 40 seconds for the same 50mb file, making me think this way is better. I've also played around with different read sizes (512, 256, 64, couple of others) but I didn't notice a difference)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload