I use this script in PHP 5.5.9:
declare(ticks = 1); pcntl_signal(SIGTERM, array($this, 'stopSending')); pcntl_signal(SIGINT, array($this, 'stopSending')); pcntl_signal(SIGUSR1, array($this, 'stopSending')); pcntl_signal(SIGUSR2, array($this, 'stopSending')); pcntl_signal(SIGQUIT, array($this, 'stopSending')); pcntl_signal(SIGHUP, array($this, 'stopSending')); public function stopSending($signals) { echo "hello"; exit(); } while (true) {
On Ubuntu 14 this works fine, but when you try to run on Ubuntu 16.04 with PHP7.0 and try to send a signal (kill PID), the PHP CLI does not stop and continues to work.
On Ubuntu 16.04, I check the pcntl extension, and this is normal:
>php -m | grep pcntl pcntl
I do not get any errors at startup, but it does not stop (or displays an echo).
Is there a problem with PHP7 and pcntl?
UPDATE
The problem is to encapsulate the while loop in the function:
function start() { while (true) { // some logic } } declare(ticks = 1); pcntl_signal(SIGTERM, "stopSending"); pcntl_signal(SIGINT, "stopSending"); pcntl_signal(SIGUSR1, "stopSending"); pcntl_signal(SIGUSR2, "stopSending"); pcntl_signal(SIGQUIT, "stopSending"); pcntl_signal(SIGHUP, "stopSending"); function stopSending($signals) { echo "hello"; exit(); } start();
This code does not stop.