PHP下载阻止其余的请求 [英] PHP download blocks rest of requests
问题描述
我使用非常简单的脚本从我的服务器下载文件:
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);
它工作正常,但浏览器下载文件时,我无法浏览网站或下载其他来自同一服务器的文件。我必须等到它完成。它发生在Chrome& Firefox和我也使用其他方法使用PHP下载文件,但是所有这些都是我有这个问题...所以我想这是服务器中的一个问题?
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??
非常感谢你提前:)
推荐答案
这是因为你正在使用PHP会话,而一个会话一个用户在一个请求中打开,同一会话不能在另一个请求中打开。
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.
在readfile()之前执行一个session_write_close()。
Do a session_write_close() before readfile().
这篇关于PHP下载阻止其余的请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!