debuggable

 
Contact Us
 

Issues with output buffering in CakePHP

Posted on 16/7/06 by Felix Geisendörfer

Output buffering is a useful way to accomblish things in php like gzipping all html output and such. A while ago I wrote about it on this blog (see "A miracle called gzip") as well.

The reason I write about it again is, that I have discovered a little issue with it in CakePHP. Because if you use:

ob_start ('ob_gzhandler')

or similar commands in your beforeFilter, you might suddenly notice that setting DEBUG > 1 in app/config/core.php will not give you the usal sql dump any longer. I'm not quite sure why this happens, but I think it's because CakePHP uses ob_buffering as well so there might be conflicts. The easiest solution I found is this one (this time as a complete code example):

if (DEBUG<2)
{            
    @ob_start ('ob_gzhandler');
    header('Content-type: text/html; charset: UTF-8');
    header('Cache-Control: must-revalidate');
    $offset = -1;
    $ExpStr = "Expires: " .
    gmdate('D, d M Y H:i:s',
    time() + $offset) . ' GMT';
    header($ExpStr);
}

I had a hard time debugging this issue today, so I hope this might saves you the trouble I had ; ).

--Felix Geisendörfer aka the_undefined

 
&nsbp;

You can skip to the end and add a comment.

ThinkingPHP » A miracle called gzip said on Jul 16, 2006:

[...] Update: I just found a little issue with this technique inside CakePHP. Read more about this here: Issues with output buffering in CakePHP [...]

PHPDeveloper.org said on Jul 17, 2006:

ThinkingPHP: Issues with output buffering in CakePHP...

...

David Garcia Watkins  said on Jan 05, 2009:

Placing this line before the call to the Dispatcher in app/webroot/index.php seems to do the trick:

ob_start("ob_gzhandler");

I've noticed no side effects with the SQL log using this method.

sridhar  said on Apr 26, 2009:

Sorry this is also not working.
Where I have to place this?

on the default.ctp file? or core.php?

This post is too old. We do not allow comments here anymore in order to fight spam. If you have real feedback or questions for the post, please contact us.