title: How can I disable gzip compression for a PHP AJAX request/response under Apache2?
body: <p>On the embedded device I'm working on, the web-pages' Javascript sends requests to local PHP files and then uses the responses to update DOM elements dynamically. Everything works fine: AJAX is cool.</p>
  
  <p>Annoyingly, though, all the responses are gzip encoded even though I'd rather they weren't (the target device's processor doesn't have much processing bandwidth). The problem is that I can't see how to disable gzip compressing the responses.</p>
  
  <p>Note that:
  (1) On the server side, I'm testing using PHP 5.3.10 and Apache/2.2.22 under Ubuntu</p>
  
  <p>(2) On the client side, I'm using Firefox 19.0 and Firebug</p>
  
  <p>(3) The PHP files are just echoing their output, i.e. I don't think they're invoking ob_gzhandler()</p>
  
  <p>(4) The JavaScript is using GET rather than POST (it's what was specified for the project)</p>
  
  <p>According to Firebug, the request headers look lke this:</p>
  
  <pre><code>Accept      text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
  Accept-Encoding gzip, deflate
  Accept-Language en-gb,en;q=0.5
  Cookie     PHPSESSID=&lt;whatever&gt;
  Host    10.0.2.15
  Referer http://10.0.2.15/pages/status.php
  User-Agent  Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:19.0) Gecko/20100101 Firefox/19.0
  </code></pre>
  
  <p>And the response headers typically look like this:-</p>
  
  <pre><code>Cache-Control   no-store, no-cache, must-revalidate, post-check=0, pre-check=0
  Connection     Keep-Alive
  Content-Encoding    gzip
  Content-Length  59
  Content-Type    text/html
  Date    Wed, 13 Mar 2013 12:08:02 GMT
  Expires Thu, 19 Nov 1981 08:52:00 GMT
  Keep-Alive      timeout=5, max=43
  Pragma   no-cache
  Server   Apache/2.2.22 (Ubuntu)
  Vary    Accept-Encoding
  X-Powered-By    PHP/5.3.10-1ubuntu3.5
  </code></pre>
  
  <p>Approaches I've already tried (but without any success):-</p>
  
  <p>(a) Preventing php files' output from being gzipped via the local .htaccess file</p>
  
  <pre><code>&lt;IfModule mod_env.c&gt;
  SetEnvIfNoCase Request_URI "\.php$" no-gzip dont-vary
  &lt;/IfModule&gt;
  </code></pre>
  
  <p>This was as per <a href="http://support.modwest.com/content/1/117/en/how-do-i-turn-off-webservers_-gzip-compression.html" rel="nofollow">http://support.modwest.com/content/1/117/en/how-do-i-turn-off-webservers_-gzip-compression.html</a> but didn't seem to have any effect, even when I restarted apache2 between calls.</p>
  
  <p>(b) Preventing php files' output from being gzipped via the /etc/apache2/httpd.conf file</p>
  
  <pre><code>&lt;Directory /myfolder&gt;
        RemoveOutputFilter php
  &lt;/Directory&gt;
  </code></pre>
  
  <p>This also didn't seem to have any obvious effect, even when I restarted apache2 between calls.</p>
  
  <p>(c) Setting the "Accept-Encoding" header to "" or "identity" using XMLHttpHeader.setHeaderRequest()</p>
  
  <p>I tried both</p>
  
  <p>xmlhttp.setRequestHeader("Accept-Encoding", "identity");</p>
  
  <p>...and...</p>
  
  <p>xmlhttp.setRequestHeader("Accept-Encoding", "");</p>
  
  <p>Neither seemed to have any obvious effect: Firebug still reports that the request header holds</p>
  
  <p>Accept-Encoding gzip, deflate</p>
  
  <p>I checked the spec for this, and it seems as though setRequestHeader() should be allowed to change the AcceptEncoding header line, so this is a bit odd. Possibly a FF security hole that's been filled?
  <a href="http://www.w3.org/TR/2006/WD-XMLHttpRequest-20060405/#dfn-setrequestheader" rel="nofollow">http://www.w3.org/TR/2006/WD-XMLHttpRequest-20060405/#dfn-setrequestheader</a></p>
  
  <p>Note that the setRequestHeader() mechanism is apparently working ok, because adding...</p>
  
  <p>xmlhttp.setRequestHeader("X-FavouriteFruit", "banana");</p>
  
  <p>...adds a line to the Firebug request output:</p>
  
  <p>X-FavouriteFruit    banana</p>
  
  <p>Basically, I'm pretty much out of ideas. How else can I stop my php responses being gzipped?</p>