PHP code example of gos / pnctl-event-loop-emitter

1. Go to this page and download the library: Download gos/pnctl-event-loop-emitter 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/ */

    

gos / pnctl-event-loop-emitter example snippets


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();

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();