views:

80

answers:

4

I noticed the other day that a new script I wrote for php 5 began outputting html that was viewable before the php script had actually finished. Did this happen with 4?

For instance, I have a long loop that echos something out with each iteration. The output was small in terms of kb, so I dont think it was lag due to the download speed. Can someone explain the difference in output?

+5  A: 

I doubt there is a difference to this regard between PHP 4 and 5, but you can get this behaviour on both versions, namely by enabling/disabling the output_buffer. Maybe the default value for PHP 5 is different than it was for PHP 4? (Haven't checked)

Cassy
+6  A: 

Maybe there a difference in the configuration of the output_buffering directive, in php.ini ?

If output_buffering is enabled, PHP will "keep" the generated output in memory (at least, if it doesn't become bigger than the size of the memory buffer), and only send it to the browser when the page's generation is finished.

If output_buffering is disabled, the ouput is sent immediatly when generated, even if the script's execution is not finished yet.

Pascal MARTIN
+1  A: 

When the data is sent, is dependant on PHP configuration, it's an output buffer, and behaves like a buffer.

Having said that, you can use the function ob_start() and ob_end_flush() to take control of the buffer. The Zend Framework does some clever stuff with output buffering for instance...

Forbes Myester
+1  A: 

The usual suspects are:

A close look at phpinfo() at a tool to see HTTP headers can help you.

Álvaro G. Vicario