2
votes

I'm converting php code to hhvm. One page in particular sometimes needs to flush() a status-message to the browser before sending some emails and a few other slow tasks and then updating the status message.

Before hhvm (using php-fpm and nginx) I used:

header('Content-Encoding: none;');

echo "About to send emails...";
if (ob_get_level() > 0) { ob_end_flush(); }
flush();

// Emails sent here

echo "Emails sent.";

So the content-encoding stops gzip being used, then the flush sends the first message, then the second message is sent when the page ends.

Using HHVM (and nginx), setting the Content-encoding header works (it shows up in the browser), but either hhvm or nginx is ignoring it and sending the page as gzipped content, so the browser interprets the content-encoding=none with binary data.

How can I disable gzip inside php code on HHVM?

(I know I could turn it off in the config files, but I want it kept on for nearly every page load except a few that will run slower.)

1
it is best to keep the content plaintext, and let nginx take care of gzipping. you could create a custom rule for nginx (for a specific url pattern) to not gzip the output. How does this sound?Sina
@Sina Thanks, to clarify: The php code isn't doing a gzip, only in nginx, but it shouldn't gzip in this case as it's being sent in 2 parts. The custom rule would be the last resort (it would mean re-structuring a lot of code, which would be annoying seeing as it had been working under our old setup.)Redzarf
I think this is probably an hhvm bug, I've posted an issue here: github.com/facebook/hhvm/issues/2641Redzarf
having exactly same issue. any solution yet? stackoverflow.com/questions/34338641/…Wudong
I gave up on it at the time, and haven't got back to trying HHVM since. Now that php7 is out and runs at a similar speed we're just going to stick with that.Redzarf

1 Answers

1
votes

While my suggestion would be to have different nginx location paths with different gzip configuration, here's a better alternative solution to achieve what you want to happen.

Better Solution:

It is often referred to as bad practice to keep a connection open (and the browser loading bar spinning) while you're doing work in the background.

Since PHP 5.3.3 there is a method fastcgi_finish_request() which flushes the data and closes the connection, while it continues to work in the background.

Now, this is unfortunately not supported yet on HHVM. However, there is an alternative way of doing this.

HHVM alternative:

You can use register_postsend_function('function_name'); instead. This closes the connection, and the given function will be executed in the background.

Here is an example:

<?php

echo "and ...";

register_postsend_function(function() {
  echo "... you should not be seeing this";
  sleep("10"); // do a lot of work
});

die();