views:

79

answers:

1

Hi there,

I have a PHP file that serves up a file, but the problem is that no matter what browser is being used, if you click on 2 links that go to 2 separate files, the second download doesn't start until the first one is complete! Any ideas?

Download Code

header('Content-Type: application/octet-stream');
header('Content-Description: File Transfer');
header('Content-Disposition: attachment; filename="'.basename($filename).'"');
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' . filesize($fullpath));
readfile($fullpath);

Example Links

  • Link 1: download.php?downloadfile=1
  • Link 2: download.php?downloadfile=2
+5  A: 

There could be different reasons for this.

  • You are using sessions. Therefor only one script at a time is allowed to modify the session. So download B can only start after download A has finished. Did you try two downloads concurrently with download A in browser A and download B in browser B? Check description for session_write_close

  • Some other HTTP issue where your browser won't open multiple connections to the server but reuse a single connection and that way of course has to wait until first request finishes.

  • Some OS/Webserver setting which only allows a very limited number of open concurrent connections either in total or per host

jitter
Michael Waterfall
@Bisbo .. i think the first point about session_write_close should solve ur problem .. i would suggest that you place that before u start sending the content of the file.
Sabeen Malik
Ah brilliant! I used session_write_close() after I finished using the session and it's working perfectly! Thanks so much for your help! Was really bugging me :-)
Michael Waterfall