在laravel 5.7应用程序中,我使用了一些在线文档安装了cboden / ratchet
composer.json :
"type": "project",
"require": {
...
"cboden/ratchet": "^0.4.1",
使用app / Classes / Socket / Base / BaseSocket.php:
<?php
namespace App\Classes\Socket\Base;
use Rachet\MessageComponentInterface;
use Rachet\ConnectionInterface;
class BaseSocket implements MessageComponentInterface {
public function onOpen(ConnectionInterface $conn) {
}
public function onMessage(ConnectionInterface $conn, $mgs) {
}
public function onClose(ConnectionInterface $conn) {
}
public function onError(ConnectionInterface $conn, \Exception $e) {
}
}
和控制台命令app / Console / Commands / ChatServer.php:
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Ratchet\Http\HttpServer;
use Ratchet\Server\IoServer;
use Ratchet\WebSocket\WsServer;
use App\Classes\Socket\ChatSocket;
class ChatServer extends Command
{
protected $signature = 'chat_server:serve';
protected $description = 'chat_server description';
public function __construct()
{
parent::__construct();
}
public function handle()
{
$this->info("Start server!");
$server= IoServer::factory(
new HttpServer(
new WsServer(
new ChatSocket()
)
),
8080
);
$server->run();
}
}
但是在控制台中运行命令时出现错误:
$ php artisan chat_server:serve
Start server!
PHP Fatal error: Interface 'Rachet\MessageComponentInterface' not found in /mnt/_work_sdb8/wwwroot/lar/Votes/app/Classes/Socket/Base/BaseSocket.php on line 7
Symfony\Component\Debug\Exception\FatalErrorException : Interface 'Rachet\MessageComponentInterface' not found
at /mnt/_work_sdb8/wwwroot/lar/Votes/app/Classes/Socket/Base/BaseSocket.php:7
3|
4| use Rachet\MessageComponentInterface;
5| use Rachet\ConnectionInterface;
6|
> 7| class BaseSocket implements MessageComponentInterface {
8|
9| public function onOpen(ConnectionInterface $conn) {
10|
11| }
Whoops\Exception\ErrorException : Interface 'Rachet\MessageComponentInterface' not found
at /mnt/_work_sdb8/wwwroot/lar/Votes/app/Classes/Socket/Base/BaseSocket.php:7
3|
4| use Rachet\MessageComponentInterface;
5| use Rachet\ConnectionInterface;
6|
> 7| class BaseSocket implements MessageComponentInterface {
8|
9| public function onOpen(ConnectionInterface $conn) {
10|
11| }
我错过了一些声明吗?还是要在app.php中添加声明? 如果我有添加配置声明,我会错过阅读文档吗?
更新的块#2:
搜索决策时,我发现我需要创建自己的服务提供商,以便在Laravel中正确注册它 我要为“ cboden / ratchet”创建自己的服务提供商,应该执行哪些步骤?这是出于我的幼虫经验...
谢谢!
答案 0 :(得分:0)
看起来像拼写错误。必须是:
use Ratchet\MessageComponentInterface;
use Ratchet\ConnectionInterface;