| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126 |
- <?php
- /**
- * Created by PhpStorm.
- * User: Administrator
- * Date: 2019/6/26
- * Time: 12:03
- */
- namespace datainf\logic;
- /*
- use App\Lib\ModelBase;
- use App\Http\Response\Response;
- use Illuminate\Database\Capsule\Manager as DB;
- */
- use datainf\lib\GlobConfigs;
- use swoole;
- class HttpDangerTimer
- {
- private $httpserver;
- private $config;
- private $redisonfig = [];
- public function __construct($config)
- {
- $this->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();
- }
- }
|