PHP Handling ^ C CLI Script

I have a php script that runs in the background 24/7. I have to interrupt it sometimes, and the point of the script is to cache transaction data in memcahced from bitcoin RPC (if you don’t know what it is, it doesn’t matter). I want a script to execute a function when a program receives a signal sent to ^ C (C control).

+5
source share
2 answers

You probably want to pcntl_signal. The signal you need to catch is SIGINT.

+20
source

If someone else is looking, I found an answer that does not require pcntl_signal.

system("stty intr ^-");, ^C script . ord(fread(STDIN, 1)) == 3 PHP .

, .

+2

All Articles