简体   繁体   中英

Downloading files with PHP - Only downloading one at a time!

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM