怎么调用timer的参数

0
<?php
require_once _DIR_ . '/Workerman/Autoloader.php';
use Workerman\Worker;
use Workerman\Lib\Timer;

$w = new \Workerman\Worker(); 
$w->onWorkerStart=function(){ 
   $timer_id=Timer::add(1, function ($client_id) {
         var_dump(time() . " " . $client_id);
},,true);

     Timer::add(10,function()use($timer_id){
           var_dump('check timer id : '.$timer_id);
            var_dump('check client id : '.$client_id); **<- 怎么把$client_id 值放这个地方**
      },,false);
}; 
?>
已邀请:

blogdaren - 常年游走于 Linux、PHP、C、VIM 之间【http://www.phpcreeper.com】

赞同来自: callplay

试试:


$worker = new Worker(); 
$worker->onWorkerStart = function($worker){
//assume $client_id = 100
Timer::add(1, function($client_id = 100)use($worker){
$worker->client_id = $client_id;
}, array(), true);

Timer::add(2, function()use($worker){
var_dump('get client id : '. $worker->client_id);
}, [], false);
};

要回复问题请先登录注册