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; post_curls($furl, ['token' => $token]); }); } //每5秒请求一次危险球审核接口 private function HandleMatch() { $config = $this->config; $token = $config['token']; $url = $config['HandleMatch']; go(function () use ($token, $url) { $furl = $url . '?token=' . $token; post_curls($furl, ['token' => $token]); }); } //每5秒请求一次 处理时间段内赛事已取消的注单1 private function HandleOrderInvalid() { $config = $this->config; $token = $config['token']; $url = $config['HandleOrderInvalid']; go(function () use ($token, $url) { $furl = $url . '?token=' . $token; post_curls($furl, ['token' => $token]); }); } 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(); } }