gpt4 book ai didi

php - 实例化期间未提供 React Loop

转载 作者:行者123 更新时间:2023-12-04 16:13:19 25 4
gpt4 key购买 nike

我正在尝试使用 Ratchet/ react 来在 PHP 中创建安全套接字。我看过很多指南和文档,但我仍然不知道为什么这不起作用。

require dirname(__DIR__) . '/composer/vendor/autoload.php';
ini_set('display_errors', 'On');
use ChatApp\Chat;

require "Chat.php";


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

$webSock = new React\Socket\Server('138.68.129.65:8443', $loop);
$webSock = new React\Socket\SecureServer($webSock, $loop, [
'local_cert' => 'absolute/path/to/cert.pem', // path to your cert
'local_pk' => 'absolute/path/to/to/key.pem', // path to your server private key
'allow_self_signed' => TRUE, // Allow self signed certs (should be false in production)
'verify_peer' => FALSE
]);

$webServer = new Ratchet\Server\IoServer(
new Ratchet\Http\HttpServer(
new Ratchet\WebSocket\WsServer(
new Chat()
)
),
$webSock
);

$webServer->run();

这是代码,错误在 IoServer.php 的第 70 行
public function run() {
if (null === $this->loop) {
throw new \RuntimeException("A React Loop was not provided during instantiation");
}

// @codeCoverageIgnoreStart
$this->loop->run();
// @codeCoverageIgnoreEnd
}

我检查了我的代码中的循环是否为空,但不是

最佳答案

似乎我从同一个 source 复制了相同的代码
在快速浏览源代码后,我发现您应该向 IoServer 构造函数添加第三个参数。所以最终的工作代码是:

require dirname(__DIR__) . '/composer/vendor/autoload.php';
ini_set('display_errors', 'On');
use ChatApp\Chat;

require "Chat.php";


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

$webSock = new React\Socket\Server('138.68.129.65:8443', $loop);
$webSock = new React\Socket\SecureServer($webSock, $loop, [
'local_cert' => 'absolute/path/to/cert.pem', // path to your cert
'local_pk' => 'absolute/path/to/to/key.pem', // path to your server private key
'allow_self_signed' => TRUE, // Allow self signed certs (should be false in production)
'verify_peer' => FALSE
]);

$webServer = new Ratchet\Server\IoServer(
new Ratchet\Http\HttpServer(
new Ratchet\WebSocket\WsServer(
new Chat()
)
),
$webSock,
$loop /** <--- here is the missing part */
);

$webServer->run();

关于php - 实例化期间未提供 React Loop,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60538079/

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