Steven Brown

Q&A – Something’s wrong with my output buffering!

by 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.


2 Comments for this entry

Leave a Reply

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!