httpserver = new \swoole\http\server($config['host'], $config['port']); $this->httpserver->set($config['sets']); $this->config = $config; $this->redisonfig = GlobConfigs::getKey('redis'); $this->httpserver->on('request', array($this, 'OnRequest')); $this->httpserver->on('WorkerStart', array($this, 'onWorkerStart')); $this->httpserver->on('task', array($this, 'onTask')); $this->httpserver->on('finish', array($this, 'onFinish')); } public function onWorkerStart($serv, $worker_id) { if ($serv->worker_id == 0) { Swoole\Timer::tick(5000, function ($id) { $this->HandleOrder(); }); } if ($serv->worker_id == 1) { Swoole\Timer::tick(60000, function ($id) { $this->HandleMatch(); }); } if ($serv->worker_id == 2) { Swoole\Timer::tick(60000, function ($id) { $this->HandleOrderInvalid(); }); } } //每5秒请求一次危险球审核接口 private function HandleOrder() { $config = $this->config; $token = $config['token']; $url = $config['HandleOrder']; go(function () use ($token, $url) { $furl = $url . '?token=' . $token; $ret = file_get_contents($furl); $this->writeLog(['data' => json_encode(['HandleOrder']), 'ret' => $ret], ''); }); } //每5秒请求一次危险球审核接口 private function HandleMatch() { $config = $this->config; $token = $config['token']; $url = $config['HandleMatch']; go(function () use ($token, $url) { $furl = $url . '?token=' . $token; $ret = file_get_contents($furl); $this->writeLog(['data' => json_encode(['HandleMatch']), 'ret' => $ret], ''); }); } //每5秒请求一次 处理时间段内赛事已取消的注单1 private function HandleOrderInvalid() { $config = $this->config; $token = $config['token']; $url = $config['HandleOrderInvalid']; go(function () use ($token, $url) { $furl = $url . '?token=' . $token; $ret = file_get_contents($furl); $this->writeLog(['data' => json_encode(['HandleOrderInvalid']), 'ret' => $ret], ''); }); } public function OnRequest($request, $response) { return; } public function onTask($serv, $task) { } public function onFinish($serv, int $task_id, $data) { } public function start() { $this->httpserver->start(); } private function writeLog($body, $ret) { go(function () use ($body, $ret) { $json_data = json_encode($body, JSON_UNESCAPED_UNICODE); $data = json_decode($body['data'], true); $game_code = isset($data['game_code']) ? $data['game_code'] : 'Timer'; $title = isset($data['title']) ? $data['title'] : 'Timer'; $msg = is_string($ret) ? $ret : json_encode($ret, 256); $now = explode(" ", microtime()); $wdata = date("Y-m-d", $now[1]); $path = LOG_PATH . DS . $wdata . DS . $game_code . DS; if (!file_exists($path)) { $ret = mkdir($path, '0755', true); if (!$ret) { echo "$path --- Log File Create false \n"; return; } } $lasttxt = date('Y-m-d H:i:s', $now[1]) . substr($now[0], 1, 5) . ' - ' . $msg . ' - ' . $json_data . "\n\n"; $file = $path . DS . $game_code . '_' . $title . '.log'; file_put_contents($file, $lasttxt, FILE_APPEND | LOCK_EX); return; }); return; } }