PHP-如何发现X-Sendfile是否可用并已安装


PHP - How to find out if X-Sendfile is available and installed?

基本上,我想向浏览器发送一个标题X-Sendfile来发送文件,但如果X-Sendfile不可用或安装在服务器上,我不想调用它。我如何在PHP中检查这一点??或者如果这是不可能在PHP中检查的,那么如何检查它是否安装了PERIOD?我宁愿检查PHP中是否存在X-Sendfile,因为这样做对我来说更容易,因为这是在其他网站和服务器上运行的包的一部分。。。也许如果我只是将它与PHP header函数一起使用,如果没有安装,它会返回一些东西??

谢谢大家:)

APACHE模块mod_xsendfile处理X-Sendfile

要检查APACHE模块mod_xsendfile是否可用并安装在服务器上,可以使用APACHE_get_modules()函数。

您不能只设置标题并检查模块是否已安装。

获取apache模块的列表并查看列表中是否有x-sendfile你可以使用http://php.net/manual/en/function.apache-get-modules.php如果没有安装,x-sendfile头将进入浏览器如果安装了,模块将过滤掉收割台。

试试这个:

    if (in_array('mod_xsendfile', apache_get_modules())) {
        header("X-Sendfile: $file");
    } else {
        error_log("Warning! mod-xsendfile is NOT INSTALLED - sending file the old fashion way.....");
        header('Content-Length: ' . filesize($file) );
        print file_get_contents($file);
    }

这是不正确的。如果相关位置的XSendFile未设置为On,但模块已加载,则会错误地认为XSendFile的使用是可用的,尽管事实并非如此。