Browser shows ERR_CONTENT_DECODING_FAILED on a PHP site
net::ERR_CONTENT_DECODING_FAILEDShort 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.
Fix it fast
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.bin2Match what you see, then jump to its fix
What does the error look like?
net::ERR_CONTENT_DECODING_FAILEDError 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.binConfirmed by php.net
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.jsConfirmed by httpd.apache.org
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
Chrome shows net::ERR_INCOMPLETE_CHUNKED_ENCODING on a PHP page
The page loads partly, then the response stops
The browser got a chunked response that ended before its final zero-length chunk, so the connection closed mid-page.
2 causes, each with a fixBack end
Android gets HTML instead of JSON from a PHP API
org.json.JSONException: Value <br of type java.lang.String cannot be converted to JSONObject
The response body is not JSON.
2 causes, each with a fixBack 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 fixBack end
Apache returns 500 with Premature end of script headers
500 Internal Server Error
Apache ran your script, but the script printed no valid HTTP header before its output.
3 causes, each with a fixBack end
Apache returns 503 or 504 because PHP-FPM did not answer in time
Error dispatching request
Apache sent the request to PHP-FPM and gave up waiting.
3 causes, each with a fixBack end
AWS SDK for PHP cannot get credentials from the instance profile metadata server
Error retrieving credentials from the instance profile metadata server.
The SDK tries the EC2 instance metadata service when it has no valid credentials from anywhere earlier in its chain.
4 causes, each with a fix