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:
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):
{
@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
You can skip to the end and add a comment.
ThinkingPHP: Issues with output buffering in CakePHP...
...
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.
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.
[...] Update: I just found a little issue with this technique inside CakePHP. Read more about this here: Issues with output buffering in CakePHP [...]