Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Node.js, PHP and APIs

Browser shows ERR_CONTENT_DECODING_FAILED on a PHP site

Errornet::ERR_CONTENT_DECODING_FAILED

Short answer

The browser was told the page is compressed, but the bytes it got could not be decompressed. On PHP sites this usually means the response was compressed twice or labelled as compressed when it was not. Use one compression layer only, and make sure no handler is mixed with zlib.output_compression.

  • Applies to PHP 8.3, Apache 2.4
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Request the page with curl and look at the Content-Encoding header, then check whether the body really is gzip.

    curl -s -D - -o /tmp/body.bin -H 'Accept-Encoding: gzip' https://example.com/page.php && file /tmp/body.bin
  2. 2Match what you see, then jump to its fix

    1. 1The code calls ob_start('ob_gzhandler') while php.ini has zlib.output_compression = OnTwo PHP compression layers are on togetherFix
    2. 2You serve .gz files with a Content-Encoding header and mod_deflate is also activeApache compresses a response that is already compressedFix

What does the error look like?

  • net::ERR_CONTENT_DECODING_FAILED
  • Error 330 (net::ERR_CONTENT_DECODING_FAILED)

Cause 1 of 2

Two PHP compression layers are on together

1Check

PHP does not support using both. Look for each of them.

php -i | grep -i "zlib.output_compression"
grep -rn "ob_gzhandler" .

2Fix

Keep only zlib.output_compression, which the manual says is preferred, and remove the ob_gzhandler call.

; php.ini
zlib.output_compression = On
; and delete: ob_start("ob_gzhandler");

3Verify

Run the curl command from the first step again; the file command should report gzip data.

curl -s -D - -o /tmp/body.bin -H 'Accept-Encoding: gzip' https://example.com/page.php && file /tmp/body.bin

Confirmed by php.net

Did this fix it?

Cause 2 of 2

Apache compresses a response that is already compressed

1Check

mod_deflate compresses on each request. If a file is pre-compressed and also passes through the DEFLATE filter, it is gzipped twice.

apachectl -M | grep -i deflate
grep -rn "SetOutputFilter DEFLATE" /etc/apache2/

2Fix

Tell mod_deflate to skip those files with the no-gzip variable, as the Apache manual does for pre-compressed content.

RewriteRule "\.css\.gz$" "-" [T=text/css,E=no-gzip:1]
RewriteRule "\.js\.gz$"  "-" [T=text/javascript,E=no-gzip:1]

3Verify

Reload Apache and request one of the files.

sudo apachectl configtest && sudo systemctl reload apache2
curl -sI -H 'Accept-Encoding: gzip' https://example.com/app.js

Confirmed by httpd.apache.org

Did this fix it?

How do I stop it coming back?

  • Pick one place for compression (PHP or the web server) and leave the other off.
  • Check responses with curl after any change to php.ini or the Apache compression rules.
  • Never set a Content-Encoding header by hand unless the body really is in that encoding.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Back end

Apache returns 403 when a URL contains %3F

a request like /page%3Fname=test is refused while /page?name=test works

Recent Apache httpd blocks a rewrite when the request contains an encoded question mark (%3F) and the rewritten target has a literal ?.

2 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.