AJAX/PHP asynchronous calculations

I am currently planning an Achievements system for my project. Achievements will be unlocked when the user actually visits the Achievements page, and any uncompleted ones will have their progress shown.It may take some time to calculate some of the achievements' progress. I came up with this idea, but I have no idea how to go about implementing it, or if it's even possible:
  • JavaScript requests achievements data via AJAX
  • PHP starts calculating achievement progress
  • For each achievement, a line is written to the output stream, of the form \[code\]ID:progress\[/code\]
  • JavaScript receives each line and shows the progress for the given achievement
How would I go about having AJAX read the \[code\]responseText\[/code\] line-by-line as it arrives, rather than all at once at the end?Additionally, if possible, I'd like for PHP to be threaded like so:
  • For each achievement:
    • If there are more than N "threads", wait for one to finish
    • Fork off a thread to calculate the current achievement and echo the result line
Is such a thing possible in PHP?Or am I just going about this completely the wrong way? Should I just send an AJAX request for each group of achievements? Or one per achievement? What would you suggest as an alternative?
 
Back
Top