alexeyshockov / symfony-signal-helper
Symfony Console helper to handle process signals (like termination)
Installs: 54 926
Dependents: 0
Suggesters: 0
Security: 0
Stars: 5
Watchers: 3
Forks: 2
Open Issues: 0
Requires
- php: ~5.6 || ~7.0
- ext-pcntl: *
- symfony/console: ~2.3 || ~3.0 || ~4.0
This package is auto-updated.
Last update: 2024-11-20 01:20:56 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. } }