globalEvent

Description:

static Event Worker::$globalEvent

This property is a global static property and represents a global event loop instance, which can be used to register read and write events for file descriptors or signal events.

Example

use Workerman\Worker;
use Workerman\Events\EventInterface;
require_once __DIR__ . '/vendor/autoload.php';

$worker = new Worker();
$worker->onWorkerStart = function($worker)
{
    echo 'Pid is ' . posix_getpid() . "\n";
    // When the process receives the SIGALRM signal, print some information
    Worker::$globalEvent->add(SIGALRM, EventInterface::EV_SIGNAL, function()
    {
        echo "Get signal SIGALRM\n";
    });
};
// Run the worker
Worker::runAll();

Testing

After Workerman is started, it will output the current process pid (a number). Run the following command in the command line:

kill -SIGALRM process_pid

The server will print out:

Get signal SIGALRM