在 Apache/PHP 中使用 X-Sendfile
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/80186/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Using X-Sendfile with Apache/PHP
提问by Don Neufeld
I can't seem to find much documentation on X-Sendfile or example code for PHP (there is some rails code).
我似乎找不到很多关于 X-Sendfile 的文档或 PHP 的示例代码(有一些 rails 代码)。
Anyone used it before and would mind giving a quick snippet of code and a brief description?
任何人以前使用过它并且介意提供一个快速的代码片段和一个简短的描述吗?
回答by Don Neufeld
X-Sendfile is an HTTP header, so you want something like this:
X-Sendfile 是一个 HTTP 头,所以你需要这样的东西:
header("X-Sendfile: $filename");
Your web server picks it up if correctly configured. Here's some more details:
如果配置正确,您的 Web 服务器会接收它。以下是更多详细信息:
回答by Garrett Albright
If tweaking the web server configuration is not an option, consider PHP's standard readfile() function. It won't be quite as fast as sendfiling, but it will be more widely compatible. Also note that when doing this, you should also send a Content-Type header at the very least.
如果无法调整 Web 服务器配置,请考虑 PHP 的标准readfile() 函数。它不会像 sendfiling 那样快,但它会更广泛地兼容。另请注意,执行此操作时,您还应该至少发送一个 Content-Type 标头。

