简体   繁体   English

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

[英]Content-Length header on HHVM FastCGI is intermittent

Maybe it's the jetlag, but I'm failing to make PHP/HHVM give me the Content-Type header when I need it. 也许是时差,但是我无法让PHP / HHVM在需要时给我Content-Type标头。

I've deployed the full stack (MySQL, HHVM, Nginx) on a Vagrant machine and I've managed to reproduce the issue on a test script: 我已经在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));
?>

If you examine the headers with curl: 如果使用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;

We have a content length header. 我们有一个内容长度标头。 However if we hit the same URL from Chrome, and get the headers from the Dev tools: 但是,如果我们从Chrome浏览器访问相同的URL,并从开发工具中获取标头,则:

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

No Content-Length header. 没有Content-Length标头。 I've also packet sniffed this to verify that the header isn't sent. 我还对数据包进行了嗅探,以验证是否未发送标头。 I can switch to PHP FPM and it sends the header. 我可以切换到PHP FPM并发送标头。

I reproduced the issue by hitting the server with: 我通过点击服务器重现了该问题:

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

HHVM enables compression by default. HHVM默认情况下启用压缩。 Disabling that gave me the header back. 禁用该功能可以使我重新获得标题。

Everything was awesome after adding this to /etc/hhvm/server.ini 将其添加到/etc/hhvm/server.ini后,一切都很棒

hhvm.server.gzip_compression_level = 0

I stumbled upon this issue/feature. 我偶然发现了这个问题/功能。 Not running HHVM though. 虽然没有运行HHVM。 Pure nginx + PHP-FPM. 纯nginx + PHP-FPM。 The thing is, if your PHP app calculates and sets Content-Lenght header field, and your nginx is configured to gzip content, it will just ditch this information and replace it by Chunked transfer encoding and GZIP headers. 关键是,如果您的PHP应用程序计算并设置了Content-Lenght标头字段,并且您的nginx配置为gzip内容,它将仅丢弃此信息,并用Chunked传输编码和GZIP标头替换它。 So do not set GZIP to a very small buffers, default is 20 bytes which does quite the opposite (end result is larger then before GZIP compression). 因此,请勿将GZIP设置为非常小的缓冲区,默认值为20个字节,这恰好相反(最终结果比GZIP压缩之前要大)。 I set it like this: gzip_min_length 1024; 我这样设置: gzip_min_length 1024;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM