2

Does anyone know how to output stuff I echo to a browser while the script is running?

I have a long loop that I'd like to output a string after every run of the loop, kind of like a progress bar, does anyone know how to do that?

1 Answer 1

4

Use the ob_flush() function:

ob_start();
//echo stuff...

ob_flush();

//echo more stuff...

ob_flush();
Sign up to request clarification or add additional context in comments.

4 Comments

I tried that and unfortunately it didn't do anything, script still executes fully then outputs everything at once to browser.
@Joe, It is probably working fine, but your browser probably isn't displaying it to you. Check it with a packet sniffer, or Fiddler or similar. Also, some servers won't push that data to you when ob_flush() is called. It is up to the server, not PHP, to do this.
@Joe so how did you fix it?
@Joe How did you fix this problem?

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.