I have a PHP script that is kicked off via ajax. This PHP script uses exec() to run a separate PHP script via the shell.
The script that is called via exec() may take 30 seconds or so to complete. I need to update the UI once it is finished.
Which of these options is preferred?
a) Leave the HTTP connection open for the 30 seconds and wait for it to finish.
b) Have exec() run the PHP script in the background and then use ajax polling to check for completion (every 5 seconds or so).
c) Something else that I haven’t thought of.
Thank you, Brian
Poll the server for updates every few seconds. When you leave connections open for that long a period of time there’s always the possibility that they may be dropped by the server or their browser (browsers timeout if an HTTP request takes too long).