When running a thread, the function registered with pcntl_signal
, never gets fired.
<?php
declare(ticks = 1);
class Task extends Thread {
public function run () {
while (1) sleep(1); // run forever
}
}
function shutdown () { // never runs :(
echo "Good bye!\n"; exit;
}
pcntl_signal(SIGTERM, 'shutdown');
$task = new Task;
$task->start();
Then, in the terminal:
# kill -TERM 123
Works fine when there is not a thread:
<?php
declare(ticks = 1);
class Task {
public function run () {
while (1) sleep(1); // run forever
}
}
function shutdown () {
echo "Good bye!\n"; exit;
}
pcntl_signal(SIGTERM, 'shutdown');
$task = new Task;
$task->run();
How can I execute some code when I send SIGTERM when running a thread? I'm using: php-5.6.7, pthreads-2.0.10, debian-7