简体   繁体   中英

Why is gzip compression not working?

This is an odd one. I am slowly rebuilding a website on a live server. Some sections of the site have been rebuilt and therefore the code is placed in a subdirectory of the home dir (ie:/mysite/newcode).

I had successfully gzipped the old site using ob_start("ob_gzhandler"); So, i have applied the exact same code for the new code. However, for some odd reason, its returning as not gzipped. I have checked on http://www.whatsmyip.org/http_compression/ and http://www.gidnetwork.com/tools/gzip-test.php . I can't quite understand why it wouldn't be gzipping the new code if the gzip handler is included as one of the very first lines (before any output) on both old and new code.

PHP 5.1.6 Apache 2.0 Centos 5

http://docs.php.net/ob_gzhandler says:

Before ob_gzhandler() actually sends compressed data, it determines what type of content encoding the browser will accept ("gzip", "deflate" or none at all) and will return its output accordingly.
Could this be the cause of your problem?

edit: You can test this with something like

 function dbg_ob_gzhandler($buffer, $mode) { error_log('dbg_ob_gzhandler invoked'); $rv = ob_gzhandler($buffer, $mode); if ( false===$rv ) { error_log('client does not support compressed content'); } return $rv; } ob_start('dbg_ob_gzhandler'); 

Found out the problem, not sure if documented anywhere...

If you use ob_start("ob_gzhandler"); and you what to flush your content, you must use ob_flush(), not flush(). Using flush will throw out the compression.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM