vali 6 年之前
父節點
當前提交
a9a1709ac2
共有 5 個文件被更改,包括 172 次插入2 次删除
  1. 17 0
      commands/bootDangerTimer.php
  2. 7 0
      commands/start_DangerTimer.sh
  3. 20 0
      configs/configs.sample.php
  4. 2 2
      datainf/lib/functions.php
  5. 126 0
      datainf/logic/HttpDangerTimer.php

+ 17 - 0
commands/bootDangerTimer.php

@@ -0,0 +1,17 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: Administrator
+ * Date: 2019/5/27
+ * Time: 9:16
+ */
+
+date_default_timezone_set('PRC');
+define('START_TIME', microtime(true));
+
+require __DIR__ . '/../vendor/autoload.php';
+\datainf\lib\boot::init();
+
+$config = \datainf\lib\GlobConfigs::getKey('httpDangerTimer');
+$ser = new datainf\logic\HttpDangerTimer($config);
+$ser->start();

+ 7 - 0
commands/start_DangerTimer.sh

@@ -0,0 +1,7 @@
+#!/bin/sh
+cd /home/swooleProV2/dataInterface/commands/
+ps -ef | grep  bootDangerTimer | awk '{print $1}' | sort -n | head -n 1 | sed  's/root//' |  xargs  kill
+sleep 1
+php bootDangerTimer.php
+sleep 1
+ps -ef | grep  bootDangerTimer

+ 20 - 0
configs/configs.sample.php

@@ -97,6 +97,26 @@ $tmp_config = [
             ],
         ],
 
+        'httpDangerTimer' => [
+            'host' => '127.0.0.1',
+            'port' => '10050',
+            'maxUsers' => 1000,
+            'sets' => [
+                'worker_num' => 4,
+                'daemonize' => true,
+                'max_request' => 20000,
+                'task_enable_coroutine' => true,
+                'dispatch_mode' => 3,
+                'debug_mode' => 1,
+                'task_worker_num' => 10,
+                'log_file' => '../logs/Danger_' . date("Ymd") . '.log',
+            ],
+            'token' => 'oclatv15689731035d84a12f550df',
+            'HandleOrder'=> 'http://stadmin.bocai108.com/HandleOrder',
+            'HandleMatch'=> 'http://stadmin.bocai108.com/HandleMatch',
+            'HandleOrderInvalid'=>'http://stadmin.bocai108.com/HandleOrderInvalid',
+        ],
+
         //调试使用
         'demo' => [
             'host' => '0.0.0.0',

+ 2 - 2
datainf/lib/functions.php

@@ -55,7 +55,7 @@ function orders_to_strval($order_array)
  * @param  string $post [请求的参数]
  * @return  string
  */
-function post_curls($url, $post)
+function post_curls($url, $post, $isPost = 1)
 {
     $curl = curl_init(); // 启动一个CURL会话
     curl_setopt($curl, CURLOPT_URL, $url); // 要访问的地址
@@ -64,7 +64,7 @@ function post_curls($url, $post)
     curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); // 模拟用户使用的浏览器
     curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1); // 使用自动跳转
     curl_setopt($curl, CURLOPT_AUTOREFERER, 1); // 自动设置Referer
-    curl_setopt($curl, CURLOPT_POST, 1); // 发送一个常规的Post请求
+    curl_setopt($curl, CURLOPT_POST, $isPost); // 发送一个常规的Post请求
     curl_setopt($curl, CURLOPT_POSTFIELDS, $post); // Post提交的数据包
     curl_setopt($curl, CURLOPT_TIMEOUT, 5); // 设置超时限制防止死循环
     curl_setopt($curl, CURLOPT_HEADER, 0); // 显示返回的Header区域内容

+ 126 - 0
datainf/logic/HttpDangerTimer.php

@@ -0,0 +1,126 @@
+<?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();
+    }
+
+}