PHP readfile()和大量下载 [英] PHP readfile() and large downloads
问题描述
在设置在线文件管理系统时,现在我已经打了一个块。
While setting up an online file management system, and now I have hit a block.
我正在尝试使用这个 readfile的修改版本:
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.
这篇关于PHP readfile()和大量下载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!