Beware: eAccelerator and PHP ZLIB Compression
On numerous LAMP servers we run, we repeatedly experienced an odd and disturbing problem. Users were fed some "random" ASCII text, instead of a rendered page, leaving them in complete frustration. After rigorous investigation, we came to a conclusion that the problem lies in a combination of PHP's zlib compression and eAccelerator. The odd part that greatly complicated debugging was that only some users experienced the problem.
eAccelerator is a "free open-source PHP accelerator, optimizer, and dynamic content cache". It's also one of the most widely used and stable implementations. The performance gains from eAccelerator are very imperssive, especially since there is no code-change involved and cache is transparent - data is real-time.
zlib comperssion is a PHP feature that compresses output (pages) and can significantly decrease both traffic usage, as well as page load times.
Unfortunately, the two do not work well together.
In our case, we decided to retain eAccelerator, since Apache was handling content compression on the front-end for us, anyway. To disable zlib comperssion in php.ini, you need to set:\ zlib.output_compression = Off
Gzip compression in Apache is enabled with a code like below, that you put in httpd.conf or .htaccess file.
<Location /> # Insert filter SetOutputFilter DEFLATE # Netscape 4.x has some problems... BrowserMatch ^Mozilla/4 gzip-only-text/html # Netscape 4.06-4.08 have some more problems BrowserMatch ^Mozilla/4\.0 no-gzip # MSIE masquerades as Netscape, but it is fine # BrowserMatch \bMSIE !no-gzip !gzip-only-text/html # NOTE: Due to a bug in mod_setenvif up to Apache 2.0.48 # the above regex won't work. You can use the following # workaround to get the desired effect: BrowserMatch \bMSI[E] !no-gzip !gzip-only-text/html # Don't compress images SetEnvIfNoCase Request_URI \ \.(?:gif|jpe?g|png)$ no-gzip dont-vary # Make sure proxies don't deliver the wrong content Header append Vary User-Agent env=!dont-vary </Location>