wokerman定时器,大神进来,给定时器动态传参数

各位我有一个数组$a = [1.5,2.8,3.6,8.8];我现在要用定时器做个任务,获取时间戳,假如当前时间戳是10000,希望可以实现过1.5s后,打印时间戳为10001.5,再过2.8s后时间戳为10004.3怎么做
已邀请:

dazhaozhao

赞同来自:

<?php
require_once __DIR__ . '/vendor/autoload.php';
use Workerman\Lib\Timer;
use Workerman\Worker;

$start = '1000';
$task = new Worker();
$task->onWorkerStart = function ($task) {

$a = [1.5, 2.8, 3.6, 8.8];
foreach ($a as $val) {
$timer_id = Timer::add($val,
function ($param) {
global $start;
$start = bcadd($start, (string) $param, 1);
echo $start . "\n";
}
, [$val], false);
}

};

// run all workers
Worker::runAll();
这样试试看

要回复问题请先登录注册