@@ -47,40 +47,40 @@ public function onOpen(Server $server, Request $request)
47
47
$ action = $ req ['action ' ] ?? '' ;
48
48
switch ($ action ) {
49
49
case 'api_excel ' : // api_excel 列表完成率
50
- while ( true ) {
51
- $ user_id = $ userInfo [ ' id ' ] ;
52
- $ server -> push ( $ request -> fd , $ this -> apiExcel ( $ user_id ));
53
- sleep (5 );
54
- $ state = ApiExcel::where ('state ' , 1 )->first ();
55
- if (!$ state ) {
56
- $ server ->push ($ request ->fd , $ this ->apiExcel ($ user_id ));
57
- break ;
58
- }
59
- // 每个用户 fd 限制请求次数
60
- $ redisKey = 'websocket_fd_ ' .$ request ->fd ;
61
- if (empty ($ this ->redis )) {
62
- $ this ->redis = Redis::connection ();
63
- }
64
- // 如果获取不到 redis 实例,使用总计数次数
65
- if ($ this ->redis ) {
66
- $ count = $ this ->redis ->incr ($ redisKey );
67
- if ($ count == 1 ) {
68
- // 设置过期时间
69
- $ this ->redis ->expire ($ redisKey , 6000 );
70
- }
71
- if ($ count > 20000 ) { // 防止刷单的安全拦截
72
- break ; // 超出就跳出循环
73
- }
74
- } else {
75
- $ count_fd = 'count_ ' .$ request ->fd ;
76
- $ this ->incrKey ($ count_fd );
77
- // 单fd超过 1000 次跳出循环
78
- if ($ this ->$ count_fd > 1000 ) {
79
- unset($ this ->$ count_fd );
80
- break ;
81
- }
82
- }
83
- }
50
+ $ user_id = $ userInfo [ ' id ' ];
51
+ $ server -> push ( $ request -> fd , $ this -> apiExcel ( $ user_id )) ;
52
+ // while (true) {
53
+ // sleep(5);
54
+ // $state = ApiExcel::where('state', 1)->first();
55
+ // if (!$state) {
56
+ // $server->push($request->fd, $this->apiExcel($user_id));
57
+ // break;
58
+ // }
59
+ // // 每个用户 fd 限制请求次数
60
+ // $redisKey = 'websocket_fd_'.$request->fd;
61
+ // if (empty($this->redis)) {
62
+ // $this->redis = Redis::connection();
63
+ // }
64
+ // // 如果获取不到 redis 实例,使用总计数次数
65
+ // if ($this->redis) {
66
+ // $count = $this->redis->incr($redisKey);
67
+ // if ($count == 1) {
68
+ // // 设置过期时间
69
+ // $this->redis->expire($redisKey, 6000);
70
+ // }
71
+ // if ($count > 20000) { // 防止刷单的安全拦截
72
+ // break; // 超出就跳出循环
73
+ // }
74
+ // } else {
75
+ // $count_fd = 'count_'.$request->fd;
76
+ // $this->incrKey($count_fd);
77
+ // // 单fd超过 1000 次跳出循环
78
+ // if ($this->$count_fd > 1000) {
79
+ // unset($this->$count_fd);
80
+ // break;
81
+ // }
82
+ // }
83
+ // }
84
84
}
85
85
return '' ;
86
86
0 commit comments