Reputation: 981
I have a php script that runs in the background 24/7. I have to occasionally terminate it, and the point of the script is to cache transaction data to memcahced from bitcoin RPC (if you don't know what that is, it is irrelevant). I want the script to execute a function when the program receives the signal sent on ^C (control C).
Upvotes: 5
Views: 2308
Reputation: 41
In case anybody else is looking, I've found an answer that doesn't require pcntl_signal.
You can use system("stty intr ^-");
to stop ^C
from exiting the script automatically. You can then capture it as ord(fread(STDIN, 1)) == 3
within PHP, and handle exiting manually.
I'm working on a library that does this.
Upvotes: 2
Reputation: 272497
You probably want pcntl_signal
. The signal you need to catch is SIGINT
.
Upvotes: 22