public static function onWorkerStart(Worker $businessWorker)
{
// use think\worker\Application;
// $app = new Application;
// $app->initialize();// 內(nèi)部通道發(fā)起倒計(jì)時(shí)
$http_worker = new Worker('http://127.0.0.1:8585');
$http_worker->reusePort = true;
$http_worker->onMessage = function (TcpConnection $connection, Request $request) {
$data = $request->get('data');
$data = json_decode($data, true);
$count = (int) $data['time'];
$userid = (int) $data['userid'];
$roomid = (int) $data['roomid'];
$gameid = (int) $data['gameid'];
$sessionid = 'room' . $roomid . 'game' . $gameid . 'userid' . $userid;
if ($count > 0) {
$_SESSION[$sessionid] = Timer::add(1, function () use (&$count, &$userid, &$roomid, &$gameid, &$sessionid) {
Gateway::sendToGroup('room' . $roomid . 'game' . $gameid, json_encode(array(
'type' => 'countdown',
'requestuid' => $userid,
'roomid' => $roomid,
'gameid' => $gameid,
'time' => $count,
)));
$count--;
if ($count < 1) {
Timer::del($_SESSION[$sessionid]);
}
});
return $connection->send('ok');
} else {
var_dump($connection);
// Timer::del($_SESSION[$sessionid]);
}
};
$http_worker->listen();
}
只開了一個(gè)進(jìn)程。要實(shí)現(xiàn)MVC代碼GET請(qǐng)求http://127.0.0.1:8585/。根據(jù)時(shí)間time如果為0就刪除上一個(gè)計(jì)數(shù)器。但是刪除不了。執(zhí)行后感覺是個(gè)死循環(huán),最后就502了。
哪位大神能幫助一下。困擾新手幾天了
你的寫法有問(wèn)題,下個(gè)請(qǐng)求就把$_SESSION[$sessionid]
覆蓋了,定時(shí)器就無(wú)法刪除了
定時(shí)器執(zhí)行一定次數(shù)后刪除自己文檔中有啊 定時(shí)器回調(diào)中刪除當(dāng)前定時(shí)器 搞幾天了咋不知道去看眼文檔,簡(jiǎn)直了