1

Imagine these two chunks of code residing in htaccess for speeding up the website.
With php 5.2.3 on apache 2.0

block A

# preserve bandwidth for PHP enabled servers
<ifmodule mod_php4.c>
    php_value zlib.output_compression 16386
</ifmodule>

block B

# compress speficic filetypes
<IfModule mod_deflate.c>
<FilesMatch "\.(js|css|eot|ttf|svg|xml|ast|php)$">
    SetOutputFilter DEFLATE
</FilesMatch>
</IfModule>

Questions that arise:

Q1. Is this the proper way to combine these two blocks A + B into 1 htaccess in the root?

Q2. Is it correct that on the second block B, |php| is used again in the mod_edflate?

hakre
  • 193,403
  • 52
  • 435
  • 836
Sam
  • 15,254
  • 25
  • 90
  • 145
  • This is effectively a duplicate [of your other question](http://stackoverflow.com/questions/5412792/preserving-bandwith-on-php4-or-php5-servers-output-compression-16386-implica), in that mod_deflate *in filter mode* is generally superior. – Charles Mar 23 '11 at 23:44
  • @Charles: Wrong. Please pay attention to **what is asked** & find the difference – Sam Mar 23 '11 at 23:59
  • @Sam, my suggestion is that you don't use extension-based selection of things to deflate in favor of content type selection by using mod_deflate in filter mode. Please pay attention to **what I said** in my answer to the linked question. Let's not play the attitude game, my friend, I'm just trying to help. – Charles Mar 24 '11 at 00:04
  • @Charles, then i must plead guilty for not understanding what you said over here... my friend... and will **pay closer attention** to what you said in the other answer (which I didnt see untill now and looks very promising, in terms of looks like it also answers this one!) – Sam Mar 24 '11 at 00:14
  • 1
    Can you clarify the 2nd question please. I don't get it. – Savageman Mar 24 '11 at 01:14
  • @Savageman, thanks for asking, well, in the second line of block B it says `FilesMatch "\....... |php|)$">` and so php is used again in there, while it does get compressed on block A as well... does this help? thank you. – Sam Mar 24 '11 at 01:31

1 Answers1

2

If mod_deflate is loaded and you can control apache configuration then you should let apache do output compression. Doing compression in php is always going to be slower. Here is my recommended config for your htaccess:

<IfModule mod_deflate.c>
    SetOutputFilter DEFLATE
    SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip
</IfModule>

I think a blacklist is more effective in this case since there are very few types of files you don't want compressed. This way you make sure to compress everything else, even those types of files you can't remember to add to a whitelist.

tony4d
  • 166
  • 3
  • thanks very much! If I understand right, my block A should block should be removed and I could opt eiher block B in my question or your solution with excluded files? Bit doesnt ZLIB do something else than DEFLATE? or is it essentially the same bandwith compresion just one called differently?? Thanks in advance mate. – Sam Apr 08 '11 at 09:42
  • They do the same thing. You should not use php to do output compression if you can use mod_deflate in apache. – tony4d Apr 08 '11 at 14:59
  • Thanks very much @tony4D another mistery solved!! Wish you a nice day and cheerful weekend. – Sam Apr 08 '11 at 16:37