Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    May 2006
    Posts
    37
    Thanks
    0
    Thanked 0 Times in 0 Posts

    while loop do function in background

    Hello,

    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):

    Code:
    <?php
    
    $i = 1;
    
    while (!file_exists($completed_file))
    {
        -- progress bar code here --
    
        if ($i == 1)
        {
           ProcessTask();
        }
    
        $i++;
    }
    
    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.
    
    ?>

  • #2
    Regular Coder
    Join Date
    Apr 2007
    Posts
    295
    Thanks
    0
    Thanked 19 Times in 19 Posts
    You'll wanna look into ob_end_flush and flush to turn output buffering off and force output


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •