gpt4 book ai didi

php - 传递给 Ratchet\Session\SessionProvider::__construct() 的参数 1 必须实现接口(interface) Ratchet\Http\HttpServerInterface

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

我正在尝试在 Ratchet 中使用 sessionProvider,以下是我的 shell 脚本:

    namespace App\Console\Commands;

use Ratchet\Session\SessionProvider;
use Illuminate\Console\Command;
use Ratchet\Server\IoServer;
use App\Http\Controllers\WebSockets\Chat;
use Ratchet\WebSocket\WsServer;
use Ratchet\Http\HttpServer;
use Symfony\Component\HttpFoundation\Session\Storage\Handler;

class ChatShell extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'command:chat';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Command description';

/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}

/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$memcached = new \Memcached();


$server = IoServer::factory(
new HttpServer(
new WsServer(
new SessionProvider(
new Chat(),
new Handler\MemcachedSessionHandler($memcached)
)
)
),
6502
);

$server->run();
}
}

发生错误说:

Argument 1 passed to Ratchet\Session\SessionProvider::__construct() must implement interface Ratchet\Http\HttpServerInterface, instance of App\Http\Controllers\WebSockets\Chat given



如何解决这个问题!

我的聊天类工具 MessageComponentInterface .

最佳答案

好的,经过长时间的搜索,我找到了解决方案,尽管 ratchet document说 WsServer 包装的 sessionProvider,sessionProvider 应该 包裹 WsServer。

经线应该是这样的:

IoServer::factory(
new HttpServer(
new SessionProvider(
new WsServer(
new Chat()
),
new Handler\MemcachedSessionHandler($memcached)
)
),
6502
);

关于php - 传递给 Ratchet\Session\SessionProvider::__construct() 的参数 1 必须实现接口(interface) Ratchet\Http\HttpServerInterface,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53446298/

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