Turn off output buffering in PHP

October 8th, 2010 by Alex Leave a reply »

This may come in handy for people who write big scripts (web scrapers, mass senders etc.). Usually, you need to know at which stage the script is, so here are some walkarounds for it:

ini_set('zlib.output_compression', 'Off');
ini_set('output_buffering ', '0');
ini_set('implicit_flush', '1');
ob_implicit_flush(true);

Additionally, you may want to use your own echo function like this:

ob_end_flush();
 
function out($s)  {
	echo $s;
	@ob_flush();
}
 
out("hi there");

Hope that helps someone. More tips to come..

This page can be found by searching for:

php output buffering offphp disable output bufferingoutput buffering offoutput buffering php offphp turn off output bufferingOutput Buffering off phpphp turn Output Buffering offphp buffering offphp output buffer off



2 comments

  1. I am behind nginx. Will this code work for me?

  2. Alex says:

    Never tried on nginx, but you can set up a test script with those configurations and run a simple cycle for couple minutes like this..

    $a = 0;
    while ($a < 300) { sleep(1); echo $a.' '; $a++; } If it times out, then most probably the code snippet doesn't work