Php gzcompress() vs. apache mod_deflate

Can someone tell me, what method is better for sending compressed files from a database driven Website:
php gzcompress() or apache2 mod_deflate?

Or would it even make sense to use both together? (But compressing a compressed file usually makes it a little larger…)

Right now I am using gzcompress() for the PHP output and apache2 mod_deflate for .js and .css.

Regards
Flözen

GZIP/delate will be better from Apache than GZIP from PHP, simply because PHP is a slow language and the compression can be intensive.

Although to be honest, this isn’t super important any more. You should put far-future expire headers on image files that never change, for better optimization.

While I’m not using Apache much anymore I would let Apache handle all the compress. For myself I use IIS which provides this functionality. I let IIS handle because it can be setup to cache selected compressed sections of my site, ones that do not change often. Saving processing cycles for more visitors.

So what compression rate would you suggest?
In PHP I used 9, should I just used the same for apache?

Try to keep everything in it’s place:

  • php controls your application (you should be able to deploy it on any server)
  • apache/iis controls the server (deflate)

For the RATE, that depends on your load and so on.
If your CPU is really low, you can keep it at 9. If you server is using to much CPU, set it lower.

OK, thanks for your suggestions!

It really depends on the specifc content being compressed, but all the times where I’ve measured, there’s generally very minimal increase in compression when going over about level 5-6 or so.