All Projects → walkor → global-timer

walkor / global-timer

Licence: other
Distributed timer for workerman.

Programming Languages

PHP
23972 projects - #3 most used programming language

global-timer

Distributed timer for workerman.

Examples

<?php
require __DIR__ . '/../vendor/autoload.php';
use Workerman\Worker;
use Workerman\GlobalTimer;

$global_channel_server = new Channel\Server('0.0.0.0', 3333);

$worker = new Worker('text://0.0.0.0:2222');
$worker->count = 4;
$worker->onWorkerStart = function($worker){
    GlobalTimer::init('127.0.0.1','3333');
    if ($worker->id == 0 ) {
        $timer_id = GlobalTimer::add(1, function() use (&$timer_id){
            echo "worker[0] tick timer_id:$timer_id\n";
        });
    }
};
$worker->onMessage = function($con, $data) use ($worker){
    $timer_id = $data;
    echo "worker[".$worker->id."] del timer_id:$timer_id\n";
    GlobalTimer::del($timer_id);
};
Worker::runAll();
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].