gpt4 book ai didi

php - 如何使用 Ratchet 在 ssl (wss) 服务器上启用 keepAlive?

转载 作者:行者123 更新时间:2023-12-04 16:14:17 24 4
gpt4 key购买 nike

我已经实现了一个 Ratchet WSS 服务器,如下所示:

$MyServer = new MyServer();

$app = new Ratchet\Http\HttpServer(
new Ratchet\WebSocket\WsServer(
$MyServer
)
);

$loop = React\EventLoop\Factory::create();

$secure_websockets = new React\Socket\Server('0.0.0.0:6190', $loop);
$secure_websockets = new React\Socket\SecureServer($secure_websockets, $loop, [
'local_cert' => '/path/to/cert.pem',
'local_pk' => '/path/to/privkey.pem',
'verify_peer' => false
]);

$secure_websockets_server = new Ratchet\Server\IoServer($app, $secure_websockets, $loop);

$secure_websockets_server->loop->addPeriodicTimer(1, function () use ($MyServer) {
// loop
}

$app->enableKeepAlive($app->loop, 30);

$secure_websockets_server->run();

服务器在没有 $app->enableKeepAlive($app->loop, 30); 的情况下运行良好,但一旦我添加它就会失败。
PHP Fatal error: Uncaught Error: Call to undefined method Ratchet\Http\HttpServer::enableKeepAlive() in /path/to/server-ssl.php:27

包裹 keepAlive()的正确方法是什么? ?

最佳答案

enableKeepAlive() 是 WsServer 类的函数,而不是 HttpServer。试试下面的代码:

$app = new Ratchet\WebSocket\WsServer($MyServer);

关于php - 如何使用 Ratchet 在 ssl (wss) 服务器上启用 keepAlive?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60999102/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com