PHP code example of neutron / signal-handler

1. Go to this page and download the library: Download neutron/signal-handler 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/ */

    

neutron / signal-handler example snippets


// mandatory to listen to signals
declare(ticks=1);
$handler = Neutron\SignalHandler\SignalHandler::getInstance();
$handler->register(array(SIGINT, SIGTERM), function () { echo "stoppin !"; exit(); });
$handler->register(SIGCONT, function () { echo "all systems go..."; });

// register a handler for SIGCONT in default namespace
$handler->register(SIGCONT, function () { echo "SIGCONT received"; });
// register a handler for SIGCONT in "a namespace"
$handler->register(SIGCONT, function () { echo "SIGCONT received"; }, 'a namespace');
// register a handler for SIGCONT in "another namespace"
$handler->register(SIGINT, function () { echo "Interrupted !"; exit(); }, 'another namespace');

// unregister all handlers in "another namespace"
$handler->unregisterNamespace('another namespace');
// unregister all SIGINT handlers in "a namespace"
$handler->unregisterNamespace('a namespace', SIGINT);

// unregister all SIGINT handlers in any namespace
$handler->unregisterSignal(SIGINT);