the relevant code for the download script:
$fp = @fopen($file, 'rb');
while(!feof($fp) && ($p = ftell($fp)) <= $end) {
if ($p + $buffer > $end) {
$buffer = $end - $p + 1;
}
echo fread($fp, $buffer);
flush();
if($limits["Max_DL"]) sleep(1);
}
fclose($fp);
while a download is in progress, any other pages for the same site dont load. but they do still load in another browser. I am thinking this has something to do with the fact that the download page is continuously "loading" so stopping other pages from loading?
any suggestions on how i can fix this? for large files i dont want the user to not be able to browse the site while they are in the process of a download
If your download script calls session_start()
at any point, you will need to call session_write_close()
before you stream your file to the user.
This closes out the PHP session file and allows users to load another page which presumably is calling session_start
(and thus is waiting for a lock on the session file).
NOTE: You can still read $_SESSION
after calling session_write_close()
, but any modification will be thrown away - you just told PHP you're done making changes to the session.
More info: http://us2.php.net/manual/en/function.session-write-close.php
PHP is not the best solution for delivering large files as you'll occupy a process on the server for each user for the entire length of their download; if you are using Apache or nginx you should look into using mod_xsendfile or XSendfile to serve files.
If that's not possible, you could always try streamlining the process of delivering the file a little by using the readfile()
function.