diff --git a/Command/GearmanJobExecuteCommand.php b/Command/GearmanJobExecuteCommand.php index 43863df..03f64d7 100644 --- a/Command/GearmanJobExecuteCommand.php +++ b/Command/GearmanJobExecuteCommand.php @@ -79,6 +79,8 @@ protected function configure() protected function execute(InputInterface $input, OutputInterface $output) { + $this->gearmanExecute->addSystemSignalListener(); + /**@var QuestionHelper $question*/ $question = $this->getHelper('question'); diff --git a/Command/GearmanWorkerExecuteCommand.php b/Command/GearmanWorkerExecuteCommand.php index b494bc8..04b6ae3 100644 --- a/Command/GearmanWorkerExecuteCommand.php +++ b/Command/GearmanWorkerExecuteCommand.php @@ -81,6 +81,8 @@ protected function configure() protected function execute(InputInterface $input, OutputInterface $output) { + $this->gearmanExecute->addSystemSignalListener(); + /** * @var QuestionHelper $question */ diff --git a/Service/Abstracts/AbstractGearmanService.php b/Service/Abstracts/AbstractGearmanService.php index 6ae260c..f3dc768 100644 --- a/Service/Abstracts/AbstractGearmanService.php +++ b/Service/Abstracts/AbstractGearmanService.php @@ -39,7 +39,7 @@ public function __construct(GearmanCacheWrapper $gearmanCacheWrapper, array $def $this->workers = $gearmanCacheWrapper->getWorkers(); if (isset($defaultSettings['job_prefix'])) { - $this->jobPrefix = $defaultSettings['job_prefix']??null; + $this->jobPrefix = $defaultSettings['job_prefix']; } } diff --git a/Service/GearmanExecute.php b/Service/GearmanExecute.php index aff01cf..cc79fe7 100644 --- a/Service/GearmanExecute.php +++ b/Service/GearmanExecute.php @@ -90,22 +90,25 @@ public function __construct(GearmanCacheWrapper $gearmanCacheWrapper, array $def $this->stopWorkSignalReceived = false; + } - /** - * If the pcntl_signal exists, subscribe to the terminate and restart events for graceful worker stops. - */ - if (false !== function_exists('pcntl_signal')) { - declare(ticks=1); - pcntl_signal(SIGTERM, [$this,"handleSystemSignal"]); - pcntl_signal(SIGHUP, [$this,"handleSystemSignal"]); + public function addSystemSignalListener(): void + { + if (extension_loaded('pcntl')) { + pcntl_async_signals(true); + + pcntl_signal(SIGTERM, [$this, 'handleSystemSignal']); + pcntl_signal(SIGINT, [$this, 'handleSystemSignal']); + pcntl_signal(SIGHUP, [$this, 'handleSystemSignal']); + + pcntl_signal_dispatch(); } } /** - * Toggles that work should be stopped, we only subscribe to SIGTERM and SIGHUP - * @param int $signo Signal number + * Toggles that work should be stopped, we only subscribe to SIGTERM,SIGINT and SIGHUP */ - public function handleSystemSignal($signo) + public function handleSystemSignal(): void { $this->stopWorkSignalReceived = true; }