I want to stop executing my command from controller action so I tried to use pcntl to achieve this.
This is my code(Command):
protected $should_stop = false;
protected function execute(InputInterface $input, OutputInterface $output)
{
pcntl_signal(SIGHUP, [$this, 'stopCommand']);
foreach($something as $row) {
pcntl_signal_dispatch();
if($this->should_stop === true) {
break;
}
...
}
}
protected function stopCommand()
{
$this->should_stop = true;
}
But when I run my command it display error:
[Symfony\Component\Debug\Exception\UndefinedFunctionException]
Attempted to call function "pcntl_signal" from namespace "AppBundle\Command".
I have no idea how to fix it, could you guys help? Also if you have any other good method how to stop executing symfony command from the controller action it would be nice if you could post the solution here.