alexeyshockov/symfony-signal-helper

Symfony Console helper to handle process signals (like termination)

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

This package is auto-updated.

Last update: 2024-04-20 00:14:09 UTC


README

Helper for Symfony Console to handle process signals (like termination).

Installation

$ composer require alexeyshockov/symfony-signal-helper

Usage

Just register the helper in your application (app/console, for example):

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

// ...

$console = new Application();

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

$console->run($input);

And use it inside your command:

    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.
        }
    }