Open jonathanernst opened 4 years ago
c77b1cddffe0f179e99a3fd225cbe6b4155ee460
I tried to adjust it.
Could you please check the operation?
Thanks for creating this extension! :+1: I hope one day brotli support will be fully integrated into PHP like gzip
Unfortunately it does not work correctly (PHP v7.4, brotli.output_compression = 0 in ini-file, brotli-1.0.6-3, php-brotli-0.14.2-1) and the error described above still exists. When reloading the script it switches between compressed and uncompressed in random order.
I also created a simple script with only echo str_repeat('abcd ', 1000);
and to my surprise also this content sometimes is compressed (although it should not be!)
Please fix, thanks!
Will not work unless Accept-Encoding: br
is sent as well as zlib.output_compression
Thanks for the quick response! I don't have any default compression on my server so output is only compressed if added to PHP script.
brotli.ini
extension = brotli.so
;brotli.output_compression = 0
;brotli.output_compression_level = -1
My browser sends Accept-Encoding: gzip, deflate, br
I installed extension, restarted Apache and made these tests. I reload page every second and check developer tools
1) Compression I replaced
if (substr_count($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip')) ob_start('ob_gzhandler');
echo "My content";
at the beginning of my script with
if (substr_count($_SERVER['HTTP_ACCEPT_ENCODING'], 'br')) ob_start('ob_brotli_handler');
echo "My content";
Expected: data is always compressed (it has worked with gzip 100% for years) Result: sometimes data is not compressed
Also sometimes there is error:
ob_start(): output handler 'ob_brotli_handler' cannot be used twice
but is not used anywhere else
2) No compression
I created script with only echo str_repeat('abcd ', 1000);
as code
Expected: data is never compressed Result: sometimes data is compressed - content length changes from 5000 (uncompressed, correct) to 19 (compressed, wrong)
What am I missing here? Thanks for any pointers!
I have confirmed that ob_brotli_handler causes an error and would like to fix it.
I've activated brotli.output_compression = On brotli.output_compression_level = 4
With nginx upstream with keepalive
With a static php-fpm pool of php7.4 behind nginx, I can make one successful request with brotli and then my pool is dead.
If I have a pool with two nodes, I can make two request and get br content and then my pool is unresponsive.
With nginx upstream without keepalive
With a static php-fpm pool of php7.4 behind nginx, I can make one successful request with brotli and then the next request is uncompressed.
If I have a pool with two nodes, I can make two request and get br content and then the next request is uncompressed.
Test with php-fpm 7.2 gives the same result.
Test with curl through nginx and php-fpm : $ curl -vvv 'https://redacted/phpinfo.php' -H 'accept-encoding: br' 2>&1 | grep content-encoding < content-encoding: br
$ curl -vvv 'https://redacted/phpinfo.php' -H 'accept-encoding: br' 2>&1 | grep content-encoding [nothing]
Test directly to php-fpm:
HTTP_ACCEPT_ENCODING=br SCRIPT_NAME=/phpinfo.php SCRIPT_FILENAME=/home/redacted/phpinfo.php QUERY_STRING=full REQUEST_METHOD=GET cgi-fcgi -bind -php7.2-fpm.jernst.sock [compressed content]
HTTP_ACCEPT_ENCODING=br SCRIPT_NAME=/phpinfo.php SCRIPT_FILENAME=/home/redacted/phpinfo.php QUERY_STRING=full REQUEST_METHOD=GET cgi-fcgi -bind -php7.2-fpm.jernst.sock [uncompressed content]
Thanks for your help and best regards.