操作
X-sendfile¶
Lighty 处理大文件下载的选项,而非由 PHP 处理。- X-Sendfile, X-LIGHTTPD-send-file (旧别名)
- X-Sendfile2 (自 1.4.24 版本起可用)
描述¶
让 Lighty 处理大文件下载,而不是使用 PHP。
详情请参阅 mod_fastcgi 页面
使用方法¶
您典型的 FastCGI 设置 + "allow-x-send-file" => "enable"
fastcgi.server = {
".php" => {
"127.0.0.1" => {
# ....
"allow-x-send-file" => "enable"
}
}
}
告诉 PHP 不要处理文件下载,而是设置一个类似这样的 HTTP 头
<?php
/**
* lighttpd's feature of X-Sendfile explained.
*
* @author Björn Schotte <schotte@mayflower.de>
*/
$file_on_harddisk = "/data/vhosts/bjoern/htdocs/acbd18db4cc2f85cedef654fccc4a4d8download.tar.gz";
$file_to_download = "download.tar.gz";
header( "Content-Disposition: attachment; filename=\"" . $file_to_download . '"' );
Header( "X-LIGHTTPD-send-file: " . $file_on_harddisk);
?>
备注¶
Lighttpd 1.4.40 及更高版本支持客户端的范围请求,结合后端 X-LIGHTTPD-send-file 响应。