HHVM FastCGI上的Content-Length标头是间歇性的

时间:2014-09-16 22:20:00

标签: php hhvm

也许这是时差,但是我无法让PHP / HHVM在需要时给我 Content-Type 标题。

我已经在Vagrant机器上部署了完整的堆栈(MySQL,HHVM,Nginx),并且我设法在测试脚本上重现了这个问题:

<?php
$file='/usr/share/doc/iptables/html/NAT-HOWTO.html'; # random test file
header('Content-Length: ' . filesize($file));
echo(readfile($file));
?>

如果用curl检查标题:

hostname:~ jsimpson$ curl -I http://vagrant/test.php
HTTP/1.1 200 OK
Server: nginx/1.4.6 (Ubuntu)
Date: Tue, 16 Sep 2014 22:09:25 GMT
Content-Type: text/html; charset=utf-8
Content-Length: 2592
Connection: keep-alive
X-Powered-By: HHVM/3.2.0
Content-Encoding: none;

我们有一个内容长度标题。但是,如果我们从Chrome访问相同的网址,并从开发工具中获取标题:

HTTP/1.1 200 OK
Server: nginx/1.4.6 (Ubuntu)
Date: Tue, 16 Sep 2014 22:14:41 GMT
Content-Type: text/html; charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
X-Powered-By: HHVM/3.2.0
Content-Encoding: gzip

没有Content-Length标头。我还要对数据包进行嗅探,以验证是否未发送标头。我可以切换到PHP FPM并发送标题。

2 个答案:

答案 0 :(得分:1)

我通过点击服务器来重现这个问题:

curl -H 'Accept-Encoding: gzip,deflate' --compressed -v http://foo/bar

HHVM默认启用压缩。禁用它会让我回头。

将此内容添加到 /etc/hhvm/server.ini

后,一切都很棒
hhvm.server.gzip_compression_level = 0

答案 1 :(得分:0)

我偶然发现了这个问题/功能。但是没有运行HHVM。纯nginx + PHP-FPM。 问题是,如果您的PHP应用程序计算并设置Content-Lenght标头字段,并且您的nginx配置为gzip内容,它将丢弃此信息并将其替换为Chunked传输编码和GZIP标头。 因此,不要将GZIP设置为非常小的缓冲区,默认为20字节,这恰好相反(最终结果大于GZIP压缩之前)。 我这样设置: gzip_min_length 1024;

相关问题