View Full Version : while loop do function in background

06-11-2007, 07:16 PM

I have a while Loop that works something like this (I've simplified it so you can see the general logic of what I'm trying to accomplish):


$i = 1;

while (!file_exists($completed_file))
-- progress bar code here --

if ($i == 1)


Basically, I want to output a progress bar while I perform a task in the background. When the task is completed it writes a $completed_file txt file, so I know when to stop the progress bar.

The problem is that when it gets to the ProcessTask() function, it stops to run that WHOLE function. So basically it sits at 10% until the ProcessTask function is completed, and then it outputs everything to the page. Instead of that I want it to run the Function in the background, allowing my progress bar to run smoothly and completely.

Is there a way to run a task/function in the background of the while loop, so my progress bar doesn't get interrupted?

Your advice/experience is very much appreciated.


mr e
06-11-2007, 07:37 PM
You'll wanna look into ob_end_flush (http://www.php.net/ob_end_flush) and flush (http://www.php.net/flush) to turn output buffering off and force output