Skip to content
This repository has been archived by the owner on May 25, 2020. It is now read-only.

GeniusesOfSymfony/PNCTLEventLoopEmitter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NOTE - This repository is no longer maintained

PNCTL Event Loop Emitter

Latest Stable Version Total Downloads License

Brings PNCTL event to event loop.

Install

composer require gos/pnctl-event-loop-emitter

Usage

use React\EventLoop\Factory;
use Gos\Component\PnctlEventLoopEmitter\PnctlEmitter;

$loop = Factory::create();

$pnctlEmitter = new PnctlEmitter($loop);

$pnctlEmitter->on(SIGTERM, function () use ($loop) {
	//do something
	
	$loop->stop();
});

$pnctlEmitter->on(SIGINT, function () use ($loop) {
	//do something
	
	$loop->stop();
});

$loop->run();

Example

Handle double CTRL+C

use React\EventLoop\Factory;
use Gos\Component\PnctlEventLoopEmitter\PnctlEmitter;

$loop = Factory::create();
$pnctlEmitter = new PnctlEmitter($loop);

$pnctlEmitter->on(SIGINT, function () use ($loop) {
	$this->logger->notice('Press CTLR+C again to stop the server');

    if (SIGINT === pcntl_sigtimedwait([SIGINT], $siginfo, 5)) {
        $this->logger->notice('Stopping server ...');

        //Do your stuff to stop the server

        $loop->stop();

        $this->logger->notice('Server stopped !');
    } else {
    	$this->logger->notice('CTLR+C not pressed, continue to run normally');
    }
});

$loop->run();