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.
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.
Note that: (1) On the server side, I'm testing using PHP 5.3.10 and Apache/2.2.22 under Ubuntu
(2) On the client side, I'm using Firefox 19.0 and Firebug
(3) The PHP files are just echoing their output, ie I don't think they're invoking ob_gzhandler()
(4) The JavaScript is using GET rather than POST (it's what was specified for the project)
According to Firebug, the request headers look lke this:
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=<whatever>
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
And the response headers typically look like this:-
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
Approaches I've already tried (but without any success):-
(a) Preventing php files' output from being gzipped via the local .htaccess file
<IfModule mod_env.c>
SetEnvIfNoCase Request_URI "\.php$" no-gzip dont-vary
</IfModule>
This was as per http://support.modwest.com/content/1/117/en/how-do-i-turn-off-webservers_-gzip-compression.html but didn't seem to have any effect, even when I restarted apache2 between calls.
(b) Preventing php files' output from being gzipped via the /etc/apache2/httpd.conf file
<Directory /myfolder>
RemoveOutputFilter php
</Directory>
This also didn't seem to have any obvious effect, even when I restarted apache2 between calls.
(c) Setting the "Accept-Encoding" header to "" or "identity" using XMLHttpHeader.setHeaderRequest()
I tried both
xmlhttp.setRequestHeader("Accept-Encoding", "identity");
...and...
xmlhttp.setRequestHeader("Accept-Encoding", "");
Neither seemed to have any obvious effect: Firebug still reports that the request header holds
Accept-Encoding gzip, deflate
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? http://www.w3.org/TR/2006/WD-XMLHttpRequest-20060405/#dfn-setrequestheader
Note that the setRequestHeader() mechanism is apparently working ok, because adding...
xmlhttp.setRequestHeader("X-FavouriteFruit", "banana");
...adds a line to the Firebug request output:
X-FavouriteFruit banana
Basically, I'm pretty much out of ideas. How else can I stop my php responses being gzipped?
it would seem you use apache on the device to serve the PHP files, which means you could try something like this in /etc/php.ini (or in .htaccess via @php_value)
zlib.output_compression = Off
in the Language options section.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.