How to do process a time consuming task in php?
Here is the problems, I have a link, something like this:
http://mydomain.com/veryLongPrcoess.php,
inside this php, I will do something very time consuming. I call it using AJAX, but after I called it, it lastly timeout, 开发者_如何学运维because the process in server is still running. It may takes 10mins or more to process it...
How can I notify the user, and tell him/her I finished the job? instead of waiting it timeout. Thank you.
One way of doing this would be to use pcntl_fork
. This will allow the long task to be run in a separate process, and you can simply send the user an email when its completed. Alternatively, you could use AJAX to poll the server to see if the task has completed?
If your script will take a long time to run, I think as well as forking the process using pcntl_fork you'll need to set_time_limit(0) this will allow the script to run as long as it needs to. If its memory inventive you might also need to overwrite the memory_limit using ini_set.
精彩评论