Page 1 of 1

Getting PHP to display steps in a long script as they happen

Posted: Mon May 11, 2009 9:47 am
by jghobrial15
Hi all,

I have a PHP script that performs several different tasks, each task can take a significantly long time (15-30 seconds).

I have the script set up so that it "echo's":
"Beginning Task 1" before the start of task 1, and then "Task 1 Complete"
"Beginning Task 2"..."Task 2 Complete" and so on...

My problem is that sometimes when I run the script (I'm using Firefox), the browser displays the steps as the script executes them - this is the behavior I want, other times, and most often, the browser displays absolutely nothing until the script is finishing running, and then all of a sudden displays all of the text at once...
"Beginning Task 1....Task 1 Complete",
"Beginning Task 2...Task 2 Complete" etc. etc.

Even if my first line of code is "echo "hello"", the browser won't display that line until the entire script is finished running.

Is there a way to force PHP to display these intermediary steps as they happen?

Thanks for your help.

Re: Getting PHP to display steps in a long script as they happen

Posted: Mon May 11, 2009 10:43 am
by Yossarian
Look up output buffering in the manual, the functions start with ob_* that flushes the buffer out to the browser.

Re: Getting PHP to display steps in a long script as they happen

Posted: Mon May 11, 2009 2:38 pm
by jghobrial15
hmmm, I've tried playing around with the output buffer, putting ob_get_contents() at various points in my script, and it showed the output properly the first time I ran the script, but has reverted back to waiting until the script is finished running ever since then...