开发者

Stopping a script and then restarting it?

There's a PHP script that I run from the command line. Outputs various information to my terminal as it chugs along.

I want to code a restart trigger for it, so that when called, it (obviously) restarts the script.

I was thinking of making it call some other file and then just die(), and have the other file call the script, but I want the script to reload in the same terminal.

Is thi开发者_StackOverflow社区s possible?


php has an analogue to the signal c function called "pcntl_signal" that lets you set up signal handlers.

in a signal handler (e.g. SIGUSR1 or SIGTSTP) you can do the restart code.

Either:

a) encode the entire body of the php script in a function, and have the signal handler merely call the function again

b) php script can exec itself [or exec $argv[0] ]

in either case, right after that call, you should call die


You can register signal handler and restart the script from the handler.

check this out http://php.net/manual/en/function.pcntl-signal.php

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜