Julian Simpson Julian Simpson - 7 months ago 15
PHP Question

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.

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:

<?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:

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:

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. 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.

Answer

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. Disabling that gave me the header back.

Everything was awesome after adding this to /etc/hhvm/server.ini

hhvm.server.gzip_compression_level = 0
Comments