A PHPCLI small program, with
while (1) {
....
}
Way to handle queue tasks (mostly written to MySQL), ask if the console kill the process
How to safely interrupt, accept kill (or CTRL + Z in the foreground) signal
Finish a task, output Byebye and then exit
Thank you
Reply content:
A PHPCLI small program, with
while (1) {
....
}
Way to handle queue tasks (mostly written to MySQL), ask if the console kill the process
How to safely interrupt, accept kill (or CTRL + Z in the foreground) signal
Finish a task, output Byebye and then exit
Thank you
If it is called when the script terminates, you can use Register_shutdown_function () or __destruct (), but the problem obviously requires process control, the signal processor.
CTRL-C sends the SIGINT signal, the default process ends, but the process itself can redefine the behavior of receiving this signal.
Ctrl-z send Sigstop signal, the process is just stopped, and then send Sigcont signal, the process continues to run, involving the command has JOBS,FG,BG.
Refer to the Process Control extension predefined constants, http://php.net/manual/zh/function.pcntl-signal.php gives a piece of code, the reference is as follows:
针对你的问题的面向过程式示例代码,当然也可以采用面向对象方式:
以上例子当执行ctrl+c或者kill时会输出
➜ ....^Cctrl+cshutdown➜ .........killshutdown
Ps-ef | grep php
will list the current working script and see the PID for that path
then Kill-9 {pid}
Don't know if there's a better way.