Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if gzip compression is enabled with PHP?

Is (function_exists('ob_gzhandler') && ini_get('zlib.output_compression')) enough ?

I want to check if the host is serving compressed pages within one of the pages :)

like image 309
thelolcat Avatar asked Feb 22 '12 15:02

thelolcat


People also ask

How do you check gzip compression is enabled or not?

Double click on the file and select headers. Under 'Response headers' you are looking for the 'Connection-Encoding' field, it will say gzip if it is enabled. NOTE: By default, Deflate is enabled on all of our servers.

How can I tell if a server is using gzip?

You can tell using Developer Tools (F12). Go to the Network tab, select the file you want to examine and then look at the Headers tab on the right. If you are gzipped, then you will see that in the Content-Encoding.

How do I test a gzip file?

If you just want to test whether or not the file is compressed use gzip --list (redirect errors if you want) and check $? The gzip -t command only returns an exit code to the shell saying whether the file passed the integrity test or not.


1 Answers

For PHP, they'll do fine.

However, if your referring to compression of pages back to clients, you'll also need to check it's enabled in apache (assuming your using apache you'll need the mod_gzip.c OR mod_deflate.c modules).

For instance: # httpd -l (apache 2)

Ive also seen mention of needing to implement .htaccess overrides in the past:

#compress all text & html:
AddOutputFilterByType DEFLATE text/html text/plain text/xml
# Or, compress certain file types by extension:
<Files *.html>
SetOutputFilter DEFLATE
</Files>
like image 159
HeavenCore Avatar answered Sep 28 '22 14:09

HeavenCore