HttpDangerTimer.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Administrator
  5. * Date: 2019/6/26
  6. * Time: 12:03
  7. */
  8. namespace datainf\logic;
  9. /*
  10. use App\Lib\ModelBase;
  11. use App\Http\Response\Response;
  12. use Illuminate\Database\Capsule\Manager as DB;
  13. */
  14. use datainf\lib\GlobConfigs;
  15. use swoole;
  16. class HttpDangerTimer
  17. {
  18. private $httpserver;
  19. private $config;
  20. private $redisonfig = [];
  21. public function __construct($config)
  22. {
  23. $this->httpserver = new \swoole\http\server($config['host'], $config['port']);
  24. $this->httpserver->set($config['sets']);
  25. $this->config = $config;
  26. $this->redisonfig = GlobConfigs::getKey('redis');
  27. $this->httpserver->on('request', array($this, 'OnRequest'));
  28. $this->httpserver->on('WorkerStart', array($this, 'onWorkerStart'));
  29. $this->httpserver->on('task', array($this, 'onTask'));
  30. $this->httpserver->on('finish', array($this, 'onFinish'));
  31. }
  32. public function onWorkerStart($serv, $worker_id)
  33. {
  34. if ($serv->worker_id == 0) {
  35. Swoole\Timer::tick(5000, function ($id) {
  36. $this->HandleOrder();
  37. });
  38. }
  39. if ($serv->worker_id == 1) {
  40. Swoole\Timer::tick(60000, function ($id) {
  41. $this->HandleMatch();
  42. });
  43. }
  44. if ($serv->worker_id == 2) {
  45. Swoole\Timer::tick(60000, function ($id) {
  46. $this->HandleOrderInvalid();
  47. });
  48. }
  49. }
  50. //每5秒请求一次危险球审核接口
  51. private function HandleOrder()
  52. {
  53. $config = $this->config;
  54. $token = $config['token'];
  55. $url = $config['HandleOrder'];
  56. go(function () use ($token, $url) {
  57. $furl = $url . '?token=' . $token;
  58. post_curls($furl, ['token' => $token]);
  59. });
  60. }
  61. //每5秒请求一次危险球审核接口
  62. private function HandleMatch()
  63. {
  64. $config = $this->config;
  65. $token = $config['token'];
  66. $url = $config['HandleMatch'];
  67. go(function () use ($token, $url) {
  68. $furl = $url . '?token=' . $token;
  69. post_curls($furl, ['token' => $token]);
  70. });
  71. }
  72. //每5秒请求一次 处理时间段内赛事已取消的注单1
  73. private function HandleOrderInvalid()
  74. {
  75. $config = $this->config;
  76. $token = $config['token'];
  77. $url = $config['HandleOrderInvalid'];
  78. go(function () use ($token, $url) {
  79. $furl = $url . '?token=' . $token;
  80. post_curls($furl, ['token' => $token]);
  81. });
  82. }
  83. public function OnRequest($request, $response)
  84. {
  85. return;
  86. }
  87. public function onTask($serv, $task)
  88. {
  89. }
  90. public function onFinish($serv, int $task_id, $data)
  91. {
  92. }
  93. public function start()
  94. {
  95. $this->httpserver->start();
  96. }
  97. }