开发者

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-开发者_StackOverflowDescription: 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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜