当我尝试下载 1.5 GB 的文件时,它会上升到 1.2 GB 并再次开始下载。此功能仅用于生产。文件下载代码:
if (file_exists($file) === true) {
if (ob_get_level()) {
ob_end_clean();
}
header('Content-Description: File Transfer');
header('Content-Type: application/zip');
header('Content-Disposition: attachment; filename=' . basename($file));
header('Content-Transfer-Encoding: binary');
header('Cache-Control: no-store');
header('Cache-Control: no-cache, no-store, must-revalidate');
header('Content-Length: ' . filesize($file));
readfile($file);
exit;
}
解决了一个问题!
要下载大文件,您可以按照此处所述调整max_execution_time和 memory_limit的值,但这种方法很糟糕,因为如果文件不断增长,设置也应该相对于它增长 - 而不是comme il faut。
我需要的解决方案在此处、此处和此处描述了使用 X-Sendfile - 上传病态文件。
简而言之,您需要安装mod_xsendfile.c库并将其包含在httpd.conf 中,修改我的问题中的 php 代码 - apache2 的标准库安装示例在这里或这里,但我需要通过 docker,那一刻如果您手动安装,则省略 docker。
码头文件:
httpd.conf:
php:
或者在我的情况下Yii2: