Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GZIP, Apache, PHP: What should I know to implement in a mature site?

Apache 2.2.17 PHP 5.3.3

Currently, my app doesn't use gzip, but I would like it to. However, I'm not sure of a few things:

  1. I know that IE6 has problems with it; no need to go back over those here.
  2. What benefits/drawbacks are there to implementing this in Apache (mod_deflate) vs PHP? Do they basically produce the same result? I assume Apache would be more efficient, is this a correct assumption?
  3. The app generates quite a few types of responses: pdf, xml, zip, xls, csv, images (see next point), and of course the normal AJAX-type stuff.
  4. I've seen that many examples choose not to gzip images, why is this? Is it due to the assumption that most images are already in a compressed format, or does it have to do with it being binary data? I do create some images dynamically, and serve others statically.
  5. I also stream audio files (wav, mp3) via a PHP mechanism; any gotchas here?

Essentially, if you've implemented gzip on a mature site, and run into problems, I'd love to know what those were, and what you did to work-around these problems. Thanks!

like image 951
ken Avatar asked Nov 21 '25 03:11

ken


1 Answers

  1. Nothing else to be said

  2. Do it in Apache, it is easy to set up and requires no change to your code. You can also set it up easily to compress css and js files if you want.

  3. Apache can be set to compress only specific file types

  4. Compressing an already compressed file will almost always result in a larger file. If you have uncompressed images, like bmps, you will get better results using a compression technique specific to images than using gzip, so you are better off just converting them to gif, png, jpg depending on your needs.

  5. I am not sure about streaming, but the same as images applies to audio. If it is already compressed, don't compress it again, and if it is not, use a compression technique specific to the type.

Basically, gzip is great for compressing text files so I would set Apache to compress those. For anything else, there are better solutions if you need it.

like image 128
Alan Geleynse Avatar answered Nov 23 '25 20:11

Alan Geleynse



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!