Reputation: 16726
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
Upvotes: 0
Views: 3989
Reputation: 16726
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.
Upvotes: 0
Reputation: 96159
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');
Upvotes: 1