From da4424231073eab0a73e2ed33bd6f34c91df5242 Mon Sep 17 00:00:00 2001 From: gzydong Date: Sun, 22 Nov 2020 23:31:21 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=9D=E5=A7=8B=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Controller/Api/V1/GroupController.php | 2 ++ app/Controller/WebSocketController.php | 2 +- app/Service/SocketRoomService.php | 11 +++++++++++ config/autoload/server.php | 2 +- 4 files changed, 15 insertions(+), 2 deletions(-) diff --git a/app/Controller/Api/V1/GroupController.php b/app/Controller/Api/V1/GroupController.php index e960921..7d22cf7 100644 --- a/app/Controller/Api/V1/GroupController.php +++ b/app/Controller/Api/V1/GroupController.php @@ -105,6 +105,8 @@ class GroupController extends CController return $this->response->fail('群组解散失败...'); } + $this->socketRoomService->delRoom($params['group_id']); + // ... 推送群消息 return $this->response->success([], '群组解散成功...'); diff --git a/app/Controller/WebSocketController.php b/app/Controller/WebSocketController.php index 4f17feb..34666b6 100644 --- a/app/Controller/WebSocketController.php +++ b/app/Controller/WebSocketController.php @@ -129,7 +129,7 @@ class WebSocketController implements OnMessageInterface, OnOpenInterface, OnClos { $user_id = $this->socketFDService->findFdUserId($fd); - // stdout_log()->notice("客户端FD:{$fd} 已关闭连接 ,用户ID为【{$user_id}】,关闭时间:" . date('Y-m-d H:i:s')); + stdout_log()->notice("客户端FD:{$fd} 已关闭连接 ,用户ID为【{$user_id}】,关闭时间:" . date('Y-m-d H:i:s')); // 解除fd关系 $this->socketFDService->removeRelation($fd); diff --git a/app/Service/SocketRoomService.php b/app/Service/SocketRoomService.php index 5c1fdde..00270a2 100644 --- a/app/Service/SocketRoomService.php +++ b/app/Service/SocketRoomService.php @@ -51,4 +51,15 @@ class SocketRoomService { return redis()->sRem($this->getRoomName($room), $members); } + + /** + * 删除房间 + * + * @param string|int $room 房间名 + * @return int + */ + public function delRoom($room) + { + return redis()->del($this->getRoomName($room)); + } } diff --git a/config/autoload/server.php b/config/autoload/server.php index 1e4513f..3248d6a 100644 --- a/config/autoload/server.php +++ b/config/autoload/server.php @@ -46,7 +46,7 @@ return [ ], 'settings' => [ 'enable_coroutine' => true, - 'worker_num' => 1, + 'worker_num' => swoole_cpu_num(), 'pid_file' => BASE_PATH . '/runtime/hyperf.pid', 'open_tcp_nodelay' => true, 'max_coroutine' => 100000,