Q&A – Something’s wrong with my output buffering!
by Steven Brown on Jul.14, 2009, under PHP, Zend Framework
Question:
Something’s wrong with my output buffering! I have a Zend Framework project with a long script and I’m trying to output stuff in the controller during the process but it doesn’t appear until the end. I tried using flush() and moving the code to the view but it made no difference. What is going on?
Answer:
First of all Apache on Windows doesn’t respond to flush(), it will always wait until the end of the request to output the result.
For other system though what you should know is that by default the Zend Framework front controller will buffer all output. This is normally fine and actually is quite useful, however there are some situations where you will want to bypass output buffering. In order to do this you should place the following in your bootstrap:
$frontController->setParam('disableOutputBuffering', true);
Now I like to do this only if a certain $_GET variable is sent so that I can apply it to any URL at will, however you might like to use a plugin to permanently disable output buffering for URLs that require it.
November 7th, 2009 on 8:34pm
did you create a plugin yet? or do you just put it in the bootstrap?
November 11th, 2009 on 4:42pm
I just have mine in the bootstrap.