Absolutely Tech

[SOLVED] Flush(), ob_flush() not working in PHP (Disabling gzip through htaccess)


Flushing the output buffer doesn’t works in PHP sometimes no matter what you do. I had this code which would never work on my server but would perfectly fine on localhost. This was the code.

<?php
include('common.php');
ini_set('output_buffering','on');
ini_set('zlib.output_compression', 0);
//ini_set('implicit_flush',1);
ob_implicit_flush();
for($i=0;$i<10;$i++) {
      echo $i;
      echo str_repeat(" ", 500);
      ob_flush();
      flush();
      sleep(1);
}
?>


I knew this had to do with Server configuration as the php code was fine. Then after searching a lot I stumbled across a page where it said that my host had recently enabled gzip for all pages, I instantly knew this was the problem.

So I made a .htaccess file in the folder where this script was and entered the following:

SetEnv no-gzip dont-vary

Saved the file. And it started buffering.

Cheers!

Category: PHP

Tagged: , , , , , ,

  • Xtian

    Thank you soooooo much!!!

    you life saver :)

  • Xtian

    Thank you soooooo much!!!

    you life saver :)

  • http://twitter.com/ArtRoman Роман

    Don’t work ((((

  • Jaxx0rr

    THANKS, UR THE BEST !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

    Dammit i could not present my awesome dos prompt processing script to my boss because it wouln’t work on server only local…

  • Test

    Thank you so much, works perfectly! I’ve spent 4 hours trying to make this work.

  • Chennaizoom

    Sorry It does not work.

  • Sam Decrock

    thx, that really did it… tried everything… but not the htaccess thing :) great !

  • http://ig2net.info/archives/720.html ob_flush,flush无效 | 自留地

Ubuntu 11.04

The next version of Ubuntu is coming soon

Follow me

Sponsors