PHP code example of mshavliuk / mshavliuk-signal-events-bundle

1. Go to this page and download the library: Download mshavliuk/mshavliuk-signal-events-bundle library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

mshavliuk / mshavliuk-signal-events-bundle example snippets


public function __construct(SignalHandlerService $service)
{
    $service->addObservableSignals(['SIGINT', 'SIGHUP']);
}

$eventDispatcher->addListener(SignalEvent::NAME, function($event, $eventName) use ($output) {
    if($event->getSignal() === SIGINT) {
        $output->writeln('Ctrl+C signal handled');
    }
});


class SignalListener
{
    protected $logger;

    public function __construct(LoggerInterface $logger)
    {
        $this->logger = $logger;
    }


    public function onSignal($event)
    {
        $this->logger->info('handle signal event', ['event' => $event]);
    }
}
bash
$ php --ri pcntl