7

I've got the mod_deflate up and running. I can throw in a something.txt file in my apache server and use curl to check it out.

curl --compressed -I /somefile.txt gives me back the following which is good and compressed:

Vary: Accept-Encoding
Content-Encoding: gzip

But if i use /some.php i get back:

Accept-Ranges: bytes
X-Powered-By: PHP/5.4.4-14+deb7u5

But no Content-Encoding: gzip, the .htaccess i used with multiple options:

SetOutPutFilter DEFLATE

Or

AddOutputFilterByType DEFLATE application/json

I also checked if the zlib compression was turned off in the php.ini and also tried to set the output buffer to off. But no matter what i try i never get the php output to be compresse by apache. The overhead from apache to zip it is less than when i use php zlib.

I see enough posts like Apache output compression working for CSS/JS but not PHP but that enables compression from php. I want apache to handle it.

I must be missing something silly here.

UPDATE: I resolved all issues, also because of the answers given. In the end it still didn't work 100%. This was due to the wrong package installed. apache2filter was used which send me on the wrong path.

Erik-Jan Riemers
  • 235
  • 1
  • 2
  • 7
  • php is application/x-httpd-php not application/json –  Nov 15 '13 at 03:11
  • in the php i actually set the header to application/json and verified it was coming in as such. I persume that it listens to the header i set. – Erik-Jan Riemers Nov 15 '13 at 08:34
  • check for php extension in your configuration, do you have something like `AddOutputFilter (.... things ...) php`? – regilero Nov 15 '13 at 12:53

3 Answers3

4

AddOutputFilterByType is a deprecated way of adding things on the output filter chain (ref here ).:

One further directive AddOutputFilterByType is still supported, but may be problematic and is now deprecated. Use dynamic configuration instead.

And you may have some problems because PHP is associated with one filter chain which does not contain the DEFLATE filter.

You could try to use the new syntax of mod_filter with FilterChain as shown in this question (in the question, not in the answers).

regilero
  • 1,470
  • 1
  • 9
  • 14
  • I added this in the .htaccess file and now i got the "Content-Encoding: gzip" back. Thanks! A hard find since the whole internet is filled with outputfiltertypes and such. – Erik-Jan Riemers Nov 15 '13 at 14:53
  • Not related to the original question, but using a load test tool like "siege" or "ab" from apache doesn't get the compressed file even though it support gzip now. – Erik-Jan Riemers Nov 15 '13 at 15:08
  • @Erik-JanRiemers: do not forget to upvato the Op question on Stack Overflow then. – regilero Nov 15 '13 at 16:34
  • 1
    "`AddOutputFilterByType` is a deprecated way" - This would seem to relate to Apache 2.2 only. It appears to have been updated (and un-deprecated) in Apache 2.4 ... "Had severe limitations before being moved to mod_filter in version 2.3.7" - https://httpd.apache.org/docs/2.4/mod/mod_filter.html#addoutputfilterbytype – MrWhite Oct 07 '20 at 16:08
2

I had this problem and ended up discovering that setting the mod_deflate options in .htaccess vs. httpd.conf led to different results. The httpd.conf settings worked for PHP when run in fastcgi or as a DSO. In the .htaccess file, PHP running as fastcgi couldn't grok the deflate directives.

So try to write the rules in your httpd.conf instead of .htaccess and see if that solves your problem (don't forget to restart your Apache after making the changes).

  • I tried both the .htaccess and the /etc/apache2/mods-enabled/deflate.conf but no luck. I did restart in between. I might want to give that fastcgi a try. Almost certain its a php <-> apache issue since apache gzip's all other files just fine. – Erik-Jan Riemers Nov 15 '13 at 07:40
  • With the deflate.conf were you able to test showing compression working for other non-PHP files? If not, did you have an include statement in your httpd.conf? ie. `Include /etc/apache2/mods-enabled/deflate.conf` Just wanting to rule out those possibilities. Otherwise, I wonder if you could test with using mod_php vs. fast-cgi to see if you get any different results. – VogonPoetLaureate Nov 15 '13 at 11:51
  • As shown in my OP i did test with curl to show that other files are indeed compressed. I need to check out the other php options and see what they do too. – Erik-Jan Riemers Nov 15 '13 at 14:45
0

Try this and see if it works for you:

AddOutputFilterByType DEFLATE application/x-httpd-php
AddOutputFilterByType DEFLATE application/x-httpd-fastphp
Lothar_Grimpsenbacher
  • 1,647
  • 3
  • 18
  • 27