I have a script that requires ~5 minutes to execute and complete. Everything takes place on one PHP page (includes, but no AJAX or anything). When the script completes, you’re emailed a file.
What I would like is for the front end to simply accept the form submission and do it’s thing behind the scenes, while pushing information through if the window remains open.
So, for instance, here would be the flow:
- Fill out a form and submit.
- Page confirms the form was submitted – free to close the window.
- If the window remains open, give ‘milestone’ updates
- Query finished
- File generated
- Email sent
The goal would be to provide information if the user waits for it, but closing the window immediately after the form submits is perfectly acceptable and the email will still be received. I know I can submit the form via AJAX, but how can I pass back interim process completions rather than just a success callback?
You’ll have to have the client (the browser) poll the server on regular intervals for updates. For example, you might have something like the following:
Then, after your form is submitted, simply call
checkStatus.