PHP readfile() 和大量下载
在设置在线文件管理系统时,现在遇到了障碍.
While setting up an online file management system, and now I have hit a block.
我正在尝试使用此 修改后的文件将文件推送到客户端读取文件的版本:
function readfile_chunked($filename,$retbytes=true) {
$chunksize = 1*(1024*1024); // how many bytes per chunk
$buffer = '';
$cnt =0;
// $handle = fopen($filename, 'rb');
$handle = fopen($filename, 'rb');
if ($handle === false) {
return false;
}
while (!feof($handle)) {
$buffer = fread($handle, $chunksize);
echo $buffer;
ob_flush();
flush();
if ($retbytes) {
$cnt += strlen($buffer);
}
}
$status = fclose($handle);
if ($retbytes && $status) {
return $cnt; // return num. bytes delivered like readfile() does.
}
return $status;
}
但是当我尝试下载 13 MB 的文件时,它的大小刚好达到 4 MB.这里会出现什么问题?这绝对不是任何形式的时间限制,因为我在本地网络上工作,速度不是问题.
But when I try to download a 13 MB file, it's just breaking at 4 MB. What would be the issue here? It's definitely not the time limit of any kind because I am working on a local network and speed is not an issue.
PHP 中的内存限制设置为 300 MB.
The memory limit in PHP is set to 300 MB.
感谢您的帮助.
推荐答案
您很可能达到了 Web 服务器设置的响应缓冲区限制.众所周知,IIS 和 FastCGI 的默认缓冲区大小为 4mb.我将通过查看网络服务器<->PHP SAPI 配置来开始您的搜索.
Most likely you are hitting the response buffer limit set by your webserver. IIS and FastCGI are known to have 4mb as the default buffer size. I would start your search with looking into the webserver<->PHP SAPI configuration.
相关文章