Tattat
Tattat

Reputation: 15778

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.

Upvotes: 3

Views: 892

Answers (2)

Alan Cole
Alan Cole

Reputation: 1695

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.

Upvotes: 1

Jack Murdoch
Jack Murdoch

Reputation: 2894

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?

Upvotes: 3

Related Questions