Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/alexeyshockov/symfony-signal-helper

Symfony Console helper to handle process signals
https://github.com/alexeyshockov/symfony-signal-helper

symfony symfony-console

Last synced: about 1 month ago
JSON representation

Symfony Console helper to handle process signals

Awesome Lists containing this project

README

        

# SignalHelper

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

## Installation

```bash
$ composer require alexeyshockov/symfony-signal-helper
```

## Usage

Just register the helper in your application (`app/console`, for example):
```php
#!/usr/bin/env php
getHelperSet()->set(new SignalHelper());

$console->run($input);
```

And use it inside your command:

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