This is a trick question, while developing a php+ajax application i felt into some long queries, nothing wrong with them, but they could be done in background.
I know that there’s a way to just send a reply to user while throwing the real processing to another process by exec(), however it dosen’t feels right for me, this might generate exploits and it’s not pratical on making it compatible with virtual servers and cross platform.
PHP offers the ob_* functions although they help on flushing the cache, but the user will keep connected until the script is running.
I’m wondering if there’s an alternate to exec to keep a script running after sending data to user and closing connection/thread with apache, or a less “dirty” way to have processing data sent to another script.
After doing some research I’ve found 3 answers for this question:
Do an ajax request with a low timeout value, once the timeout is reached JS will proceed to the next step while php, in background with
ignore_user_abortenabled, will keep processing.Break apart slow processes from the script that directly answers to the user doing a immediate reply or partial reply (if possible, depending on the case), storing the slow process variables into a _SESSION or database, sending it to worker by cURL with low timeout value OR having a cron task to call workers.
Use Gearman.