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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jghobrial15
Forum Newbie
Posts: 2
Joined: Mon May 11, 2009 9:40 am

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

Post 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.
Yossarian
Forum Contributor
Posts: 101
Joined: Fri Jun 30, 2006 4:43 am

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

Post by Yossarian »

Look up output buffering in the manual, the functions start with ob_* that flushes the buffer out to the browser.
jghobrial15
Forum Newbie
Posts: 2
Joined: Mon May 11, 2009 9:40 am

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

Post 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...
Post Reply