From 063b8fac4c50201dc567fce832972f9355f3e541 Mon Sep 17 00:00:00 2001 From: wanghongjun <1445693971@qq,com> Date: Thu, 27 Jul 2023 19:44:03 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/ws_task.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/web/ws_task.php b/web/ws_task.php index 79f8fde..2ba01d0 100644 --- a/web/ws_task.php +++ b/web/ws_task.php @@ -11,14 +11,15 @@ require_once __DIR__ . '../../source/thinkphp/library/think/Config.php'; require_once __DIR__ . '../../source/application/common.php'; $config = require_once __DIR__ . '../../source/application/database.php'; -$dm = new Dm($config['connections']['dm']); // 注意:这里与上个例子不同,使用的是websocket协议 $ws_worker = new Worker("websocket://0.0.0.0:2000"); // 启动4个进程对外提供服务 $ws_worker->count = 4; // 当收到客户端发来的数据后返回hello $data给客户端 -$ws_worker->onMessage = function(TcpConnection $connection, $data) use($dm) { +$ws_worker->onMessage = function(TcpConnection $connection, $data) use($config) { + # 数据库链接不能在主进程,方法外是主进程 + $dm = new Dm($config['connections']['dm']); $param = json_decode(html_entity_decode($data),true); $returnData = ['code' => 0, 'msg' => 'error:请求失败'];