centenial Posted June 11, 2007 Share Posted June 11, 2007 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): <?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. Link to comment https://forums.phpfreaks.com/topic/55111-do-two-tasks-at-once/ Share on other sites More sharing options...
kenrbnsn Posted June 11, 2007 Share Posted June 11, 2007 Progress bars which are updated as a script is doing something are not done in PHP (AFAIK). They can be done in Javascript and the PHP can be done via AJAX. Ken Link to comment https://forums.phpfreaks.com/topic/55111-do-two-tasks-at-once/#findComment-272471 Share on other sites More sharing options...
Psycho Posted June 11, 2007 Share Posted June 11, 2007 You can only implement a progress bar if the process has some way of reporting back it's progress. Since I don't know what ProcessTask() does, it's impossible to say wether it is doable or not. As kenrbnsn stated, you would need javascript to do this, but you could implement a Javascript + PHP solution (aka, AJAX) to implement this. Now, if your ProcessTask() function can be broken down into smaller tasks, then you could have those tasks fire in succession reporting back to the page via AJAX and updating the progress that way. Link to comment https://forums.phpfreaks.com/topic/55111-do-two-tasks-at-once/#findComment-272475 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.