Ryan Ryan - 1 month ago 24
PHP Question

gzip compression with gzhandler php for 4kb file

I wanted to implement a gzip compression functionality for json output that
my php script does, for a quicker way I decided to gzip the json content
via this function

ob_start("ob_gzhandler");


The Original file json content output is around 4kb uncompressed, and it
becomes 0.7kb after compression.

Does it make any sense to compress at such small file size or I should not
compress at all, as it won't make any significant difference on the speed
of download and it might be a bad idea to put more strain on my vps cpu.

Answer

If you are running Apache and have mod_deflate you can add the following to your .htaccess.

AddOutputFilterByType DEFLATE text/json application/json 

For NGINX you can add the following to your site.conf file.

gzip on;
gzip_disable "MSIE [1-6]\.(?!.*SV1)";
gzip_vary on;
gzip_types text/json application/json;