I have a symfony console command that is continuously cycling
protected function execute(InputInterface $input, OutputInterface $output)
{
pcntl_signal(SIGHUP, [$this, 'stopCommand']);
$this->shouldStop = false;
while (true) {
pcntl_signal_dispatch();
if ($this->shouldStop) {
break;
}
sleep(60);
}
}
protected function stopCommand()
{
$this->shouldStop = true;
}
I would like to stop it from the controller
public function stopAction()
{
posix_kill(posix_getpid(), SIGHUP);
return new Response('ok');
}
but I do not know why it does not work.
source
share