alexeyshockov/symfony-signal-helper

Symfony控制台助手,用于处理进程信号(如终止)

v1.2.0 2019-02-19 10:19 UTC

This package is auto-updated.

Last update: 2024-09-20 00:58:45 UTC


README

Symfony控制台助手,用于处理进程信号(如终止)。

安装

$ composer require alexeyshockov/symfony-signal-helper

用法

只需在您的应用程序中注册此助手(例如,使用app/console)

#!/usr/bin/env php
<?php

// ...

$console = new Application();

$console->getHelperSet()->set(new SignalHelper());

$console->run($input);

然后在您的命令中使用它

    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $helper = $this->getHelper('signal');
        $helper->listen();
        
        while (true) {
            if (count(array_intersect([SIGINT, SIGTERM], $helper->takeSignals())) > 0) {
                // Stop by any of SIGINT or SIGTERM.
                break;
            }
            
            // Some business logic.
        }
    }