Skip to content

[READ-ONLY]The signal component for Hyperf Command.

License

Notifications You must be signed in to change notification settings

friendsofhyperf/command-signals

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

36 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Command Signals

Latest Stable Version Total Downloads License

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

Contact

License

MIT

About

[READ-ONLY]The signal component for Hyperf Command.

Resources

License

Security policy

Stars

Watchers

Forks

Packages

No packages published

Languages