小编gha*_*ibi的帖子

停止Symfony控制台命令

我有一个连续循环的Symfony控制台命令

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;
}
Run Code Online (Sandbox Code Playgroud)

我希望我能阻止他离开控制器

    public function stopAction()
{ 
    posix_kill(posix_getpid(), SIGHUP);

    return new Response('ok');
}
Run Code Online (Sandbox Code Playgroud)

但我不知道为什么它不起作用

console command symfony

4
推荐指数
1
解决办法
1528
查看次数

标签 统计

command ×1

console ×1

symfony ×1