friendsofhyperf / command-signals
The signals component for Hyperf Command.
Fund package maintenance!
huangdijia
hdj.me/sponsors
Requires
- php: >=8.1
- hyperf/context: ~3.1.0
- hyperf/engine: ^2.0
- hyperf/support: ~3.1.0
Suggests
- ext-swoole: >=4.6.0
- ext-swow: >=0.1.0
- dev-main / 3.1.x-dev
- v3.1.48
- v3.1.41
- v3.1.31
- v3.1.28.1
- v3.1.27
- v3.1.17
- v3.1.15
- v3.1.14.1
- v3.1.14
- v3.1.1
- v3.1.0
- v3.1.0-rc.4
- v3.1.0-beta.20
- v3.1.0-beta.15
- v3.1.0-beta.9
- v3.1.0-beta.3
- v3.1.0-beta.1
- 3.0.x-dev
- v3.0.119.1
- v3.0.119
- v3.0.85
- v3.0.80
- v3.0.70
- v3.0.60
- v3.0.55
- v3.0.52
- v3.0.51
- v3.0.49
- v3.0.44
- v3.0.42
- v3.0.35
- v3.0.14
- v3.0.2
- v3.0.0
- v3.0.0-rc.16
- v3.0.0-rc.9
- v3.0.0-rc.8
This package is auto-updated.
Last update: 2024-12-04 02:41:26 UTC
README
The signals component for Hyperf Command.
Requirements
- PHP >= 8.0
- Hyperf >= 3.0
Installation
composer require friendsofhyperf/command-signals
Usage
namespace App\Command; use FriendsOfHyperf\CommandSignals\Traits\InteractsWithSignals; use Hyperf\Command\Annotation\Command; use Hyperf\Command\Command as HyperfCommand; use Psr\Container\ContainerInterface; #[Command] class FooCommand extends HyperfCommand { use InteractsWithSignals; public function __construct(protected ContainerInterface $container) { parent::__construct('foo'); } public function configure() { parent::configure(); $this->setDescription('Hyperf Demo Command'); } public function handle() { $this->trap([SIGINT, SIGTERM], function ($signo) { $this->warn(sprintf('Received signal %d, exiting...', $signo)); }); sleep(10); $this->info('Bye!'); } }
Run
Ctrl + C
$ hyperf foo ^CReceived signal 2, exiting...
killall php
$ hyperf foo Received signal 15, exiting... [1] 51936 terminated php bin/hyperf.php foo