PHP download blocks rest of requests

空扰寡人 提交于 2019-12-01 07:24:13

问题


I am downloading files from my server using a very simple script:

header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.basename($fichero));
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($file));
ob_clean();
flush();
readfile($file);

It works fine, but while the browser is downloading the file I cannot browse through the site or downloads other files from the same server. I have to wait until it finishes. It happens in Chrome & Firefox and I have also used other methods to download files with PHP, but with all of them I have this problem...so I suppose it's a problem in the server??

Thank you very much in advance :)


回答1:


This is because you are using PHP sessions, and while a session for one user is opened in one request, the same session cannot be opened in an other request.

Do a session_write_close() before readfile().



来源:https://stackoverflow.com/questions/7077635/php-download-blocks-rest-of-requests

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!