Anyone know how to close the connection (besides just flush()?), but keep executing some code afterwards.
I don’t want the client to see the long process that may occur after the page is done.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You might want to look at
pcntl_fork()— it allows you to fork your current script and run it in a separate thread.I used it in a project where a user uploaded a file and then the script performed various operations on it, including communicating with a third-party server, which could take a long time. After the initial upload, the script forked and displayed the next page to the user, and the parent killed itself off. The child then continued executing, and was queried by the returned page for its status using AJAX. it made the application much more responsive, and the user got feedback as to the status while it was executing.
This link has more on how to use it:
If you can’t use
pcntl_fork, you can always fall back to returning a page quickly that fires an AJAX request to execute more items from a queue.