tags:

views:

41

answers:

4

Hey, well I don't really know how to describe this but here's my current situation.

On my old host, I could have a loop going and echo things in the loop. As the code was running that loop, the text i was echoing would appear right away and I could see things happening.

Now though, on my current host if I have a loop like that I only see the text that was being echoed once the loop is done and the script is fully done executing.

I was just wondering if anyone knows why?

Thanks!

edit: output buffering and output compression is off.

+1  A: 

Do you use flush() ? If you do, maybe the server caches the response and sends it all at once, ask your webhoster

Tobias P.
+1  A: 

Output buffering my be on by default in the server config. As Tobias says, consult you webhost.

nikc
+1  A: 

As has been stated, output buffering is likely enabled by the webhost in php.ini.

I believe you can inspect this yourself (though, it's possible for the webhost to disable access to the function):

echo ini_get('output_buffering');

Edit: some useful links

http://php.net/manual/en/outcontrol.configuration.php

http://php.net/manual/en/book.outcontrol.php

George Marian
+1  A: 

As others have said, it sounds like output buffering is on by default on your host.

You can turn it off programatically, using ob_end_flush() (which sends any buffered output), or ob_end_clean() (which will discard any output). Calling one of those functions early in your code (at the top of your script, or in some config file, for example) will get you at least part of the way there.

You may also be able to turn off output buffering in php.ini, or by setting php_value output_buffering Off in an .htaccess file, if you wanted to turn it off globally.

As Tobias P. points out, you can then use flush() to (try to) force whatever PHP is hooked up to (apache, CGI etc) to flush the output as well.

timdev