I suspect this question will seem too… silly, but I’m trying to get my head around a nice solution and I’m kinda stuck.
So, here’s my situation :
- I’m using Ajax to perform a series of tasks. Actually, I’m queuing (or parallely at times, doesn’t really matter to me) 1 or more requests.
- Show the progress as a percentage (1 out of X tasks performed)
- When finished, show the final result.
What I’m trying to do :
- Instead of having 3-4 different tasks running (= 3-4 different PHP scripts called asynchronously via Ajax), I would like to have just 1 (= 1 script) – in other words, combine the X scripts into one. (That’s easy).
Issues I’m facing :
- How could I still report the percentage complete (1 out of X tasks)?
Any ideas?
If you have the request dropped into a database by your original ajax, then kick off the script, you will still have time (assuming the request takes some time to complete) for subsequent tasks to be dropped into the same database to be picked up by the script that is still running.
As for reporting it, perhaps run a quick jquery to see how many items are in the queue? Alternately have the task.php file update the database (possibly another table even) to say how many jobs it has completed and how many are currently still in the queue.