Mailing List Archive

brotli with Apache and PHP-FPM - possible?
I've tried enabling brotli with Apache on Ubuntu 20.04 (running Apache
2.4.41). Brotli works, but not for content generated with PHP.

It works for HTML files:

$ curl -v -H "Accept-Encoding: gzip, deflate, br"
https://server.tld/pp.html 2>&1 | grep content-encoding
< content-encoding: br

But does not work if it's PHP - in this case, the content is compressed
with "gzip":

$ curl -v -H "Accept-Encoding: gzip, deflate, br"
https://server.tld/pp.php 2>&1 | grep content-encoding
< content-encoding: gzip

Curiously, it does work with PHP if I specify "br" as the only value in
"Accept-Encoding" (browsers however use "gzip, deflate, br"):

$ curl -v -H "Accept-Encoding: br" https://server.tld/pp.php 2>&1 | grep
content-encoding
< content-encoding: br

So, what is the problem here?


I've enabled brotli by running:

a2enmod brotli

and adding the following part to the vhost (followed by apache restart):

AddOutputFilterByType BROTLI_COMPRESS text/html text/plain text/xml
text/css text/javascript application/x-javascript application/javascript
application/json application/x-font-ttf application/vnd.ms-fontobject
image/x-icon


Tomasz Chmielewski

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org
Re: brotli with Apache and PHP-FPM - possible? [ In reply to ]
[...]
> But does not work if it's PHP - in this case, the content is compressed
> with "gzip":
>
> $ curl -v -H "Accept-Encoding: gzip, deflate, br"
> https://server.tld/pp.php 2>&1 | grep content-encoding
> < content-encoding: gzip
>
> Curiously, it does work with PHP if I specify "br" as the only value in
> "Accept-Encoding" (browsers however use "gzip, deflate, br"):

Sounds like you need to enforce the correct order of the filters. I don't know
how to do that using "AddOutputFilterByType", but with "FilterProvider",
the example below should work. While you're there, you can also enable
mod_buffer to improve the compression ratio:

BufferSize 131072
FilterProvider buffer BUFFER "resp('Transfer-Encoding') ==
'' && %{CONTENT_TYPE} =~ m|^text/|"
FilterProvider gzip_compression DEFLATE "resp('Transfer-Encoding') ==
'' && %{CONTENT_TYPE} =~ m|^text/|"
FilterProvider brotli_compression BROTLI_COMPRESS
"resp('Transfer-Encoding') == '' && %{CONTENT_TYPE} =~ m|^text/|"

FilterChain buffer brotli_compression gzip_compression


rainer

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org