2

I have been trying to get my server to be able to flush an echo or print after sleeping and have been unsuccessful. Im using PHP 5.3.24 under Windows. There are literally dozens and dozens of suggestions out there, just about all of which I tried, none of which has worked. Here is some code that I thought may have worked:

ob_implicit_flush(true);
ob_end_flush();
for ($i=0; $i<10; $i++) {
   echo $i.'<br>';
   sleep(1);
}

This code will not do anything for 9 seconds and then output everything.

I have tried:

-outputting over 1000 characters at the top of the page since there was a suggestion that the browser my be caching,

-added header( 'Content-type: text/html; charset=utf-8' ); header("Cache-Control: no-cache, must-revalidate");header ("Pragma: no-cache");

-used flush(); and ob_flush(); commands,

-made output_buffering = Off, zlib.output_compression = Off, and implicit_flush = Yes (or implicit_flush = On, seen both examples) in the php.ini,

-also tried @ini_set('zlib.output_compression',0); @ini_set('implicit_flush',1); @ob_end_clean(); set_time_limit(0);

Plus others that I am probably forgetting.

Is there something I am missing? Thanks.

1
  • I should have mentioned before, I have this running in IIS 7 in windows Server 2008 R2. Commented Sep 30, 2013 at 18:28

1 Answer 1

1

Looks like browser caching. Try this (tested successfully):

ob_implicit_flush(true);
ob_end_flush();
for ($i=0; $i<10; $i++) {
   echo $i.'<br>';
   echo str_repeat(' ', 1024);
   sleep(1);
}

Not a fine solution, but it proves that you simple have to put more characters into the browser buffer.

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks for replying, but unfortunately that did not work. I have tried padding the characters before the loop and during (as per your code), but it still does not work.
Have you tried to do a raw http request by hand? In linux, 'echo -e "GET /script.php HTTP/1.0\r\nHost: mydomain.com\r\n\r\n" | nc mydomain.com 80' would do it. Just to see if its buffered in the webserver of in the browser. In my configuration (Apache and Firefox), your code got buffered in Firefox and mine worked. The command above should show, if its an browser or IIS related problem
Thanks. I ran it from the windows command line and it works how it should, even if I remove the flush commands from the code. That removes the php install out of the equation, but it could still be an IIS issue or a browser issue. But thank you, it is further than I have gotten before.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.