0

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?

8
  • 1
    Do you mean the user shuts down their browser, or they shut down the server? Commented Feb 19, 2015 at 12:53
  • ^ @halfer That sounds like attack on the server Commented 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. Commented Feb 19, 2015 at 12:55
  • I want, if user shut down their operating system. still php code should be executed. is it possible? Commented 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 again Commented Feb 19, 2015 at 13:06

3 Answers 3

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

i found that register_shutdown_function can do something like this. but when i put this in code , whole script stop working. please guide
1

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.

6 Comments

i found that register_shutdown_function can do something like this. but when i put this in code , whole script stop working. please guide.
Im not to clear on what exactly your trying to do. Is the user shuting down the server? Or are your running on a local through xamp or something like that? Or is he just logging out of your site?
I am working on a website. there is a user request process, which will take around 30 mins to finish. enough time to do anything else. So i modified my code so that, script will continue executing if user close the tabs or browser, But if user need to shut down his operating system so this process is killed. Thats i don't want.
But is the code running in the users machine? Or is it in a remote server? Because normal websites dont stop working if the user shutsdown his machine.
On user machine. all user request process is stop working after shutdown in my website. Please explain how other website is still working. i ready don't have knowledge about it.
|
0

The script cannot continue if the system is shut down. There is no system that "works" so the php script can continue it's job :)

2 Comments

user shutdown the system OP means user system
That makes a lot more sense :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.