events.php中onMessage和onClose如何使用同个数据库操作类或全局变量呢?

phper

events.php中onMessage和onClose如何使用同个数据库操作类(只实例化一次)或全局变量呢?

$DataBaseConn=null;
$gateway_text->onWorkerStart = function($connection)
{   
    global $DataBaseConn;
    $DataBaseConn="test";
}

下面这个打印为空

public static function onMessage($client_id, $message){
     global $DataBaseConn;
     echo $DataBaseConn;
}
3565 1 0
1个回答

walkor 打赏

业务是运行在BusinessWorker进程的,

$businessworker->onWorkerStart = function($connection)
{
    global $DataBaseConn;
    $DataBaseConn="test";
}
年代过于久远,无法发表回答
×
🔝