I have to execute a method in background; the whole script takes around 30 minutes to finish. I make this as background process, my script is still working after the page is refreshed or close browser. But how to keep executing script if user shuts down their system?
-
1Do you mean the user shuts down their browser, or they shut down the server?halfer– halfer2015-02-19 12:53:46 +00:00Commented Feb 19, 2015 at 12:53
-
^ @halfer That sounds like attack on the serverVeeeneX– VeeeneX2015-02-19 12:54:36 +00:00Commented Feb 19, 2015 at 12:54
-
1@VeeeneX: I think the OP means simply that the browser is shut down. But they could be talking about an office that shuts down and computers/servers are turned off by users who normally access them via a browser (and that the script needs to resume when the machine is turned back on). I am sure he/she will clarify.halfer– halfer2015-02-19 12:55:38 +00:00Commented Feb 19, 2015 at 12:55
-
I want, if user shut down their operating system. still php code should be executed. is it possible?user3337174– user33371742015-02-19 12:59:17 +00:00Commented Feb 19, 2015 at 12:59
-
I think his running the code on a local server on the clients computer. And if its that then he should refactor his code to be resumable and make it pause once the user turns off the system and resume once he starts it againBVJ– BVJ2015-02-19 13:06:26 +00:00Commented Feb 19, 2015 at 13:06
3 Answers
You would have to design the script in such a way that is resumable. This way, when the machine is rebooted a daemon can resume your script and it would continue working.
Of course (and I assume you knew that), you can't make the script continue to run on a machine that is turned off.
1 Comment
What do you mean by shut down the system? He turns off the server or logs out of your application? If its the first you could set up a cronjob to run when the user is about to shut down the system. You could code it into your "exit" button (if you have one) and scheduel a cron job to execute your script the next day. If its the latest the just use an asynchronic script in php.