while a user is downloading, why cant they load another page?

Go To StackoverFlow.com

0

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

2012-04-05 00:42
by cwal
this seems to be a http server issue. Which server are you using and if it is apache, which php plugin are you using? If I am right, this should go to serverfault.co - d_inevitable 2012-04-05 00:45
Apache version 2.2.19 and PHP version 5.2.17 but if i dowload the file "directly" (not thru a php script) i dont encounter this problem, also other pages/sites hosted on the same server load correctly, its really just any page associated with this user system (since downloading requires being logged in - cwal 2012-04-05 00:49
Are you using apache-mpm-working? What user system would that be that you refer to? PHP CGI or MOD_php? Not that I know much of all these, but usually what you mention shouldn't happen - d_inevitable 2012-04-05 00:56
the user system is usercake, based off cakePH - cwal 2012-04-05 01:05


3

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

2014-01-14 18:19
by DOOManiac
I have long since dropped this project, although I do still have the source it is no longer being hosted anywhere. This answer seems to make the most sense, but cannot accept it since I cannot test it. Thank you - cwal 2014-01-14 21:57


0

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.

2012-04-05 00:59
by NoCoolName_Tom
well i use php since i need to restrict downloads to logged in users only, make sure they are dowloading only files they have access to, throttle their download speeds... i will research readfile now thank - cwal 2012-04-05 01:01
Ads