AJAX (prototype/php) getting partial status updates during script execution
-
03-07-2019 - |
Question
I have a process I want to run in the background of a page. The process will take a while to run, lets say a few minutes.
I have it set up so that from the page I can click on a button to start the process off, wait a bit and then it will finish and I can have the page update notifying me that the process was run successfully. I'm doing this with prototype and php.
What I want to do is have status updates while the process is running. So it could update a the page letting me know how many records have been processed so far or update a status bar or something like that.
Is this possible? I'm just not a huge JS guru and I can do the basic functionality I've already described but was wondering if it was possible to extend it to do this little extra bit as I haven't had any luck googling or looking through the docs.
Solution
With just PHP you'll pretty much end up doing polling. You'll need to spawn your long-running process in the background, and for example write to a database of file what it's progress is.
The browser can then call a different php script every x seconds, which reports back with this status.
Polling sucks though, but that's what you're stuck with, with PHP.