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:
ID:progress
How would I go about having AJAX read the responseText
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:
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?
You could achieve this in modern ES5 browsers by using a combination of XHR2 Progress Events on the client and HTTP Chunked Transfer Encoding on the server - this Stack Overflow post goes into more detail.
Personally, I would say this approach is a little over-engineered. If it's going to take less than a couple of seconds to fetch the player achievements the first time (presuming you will cache it for subsequent requests in a given time period) then I would just make the player wait whilst they download and look to optimise this once I had enough users to warrant it :)