小编sha*_*man的帖子

如何纠正棘轮中的[PHP致命错误:未找到接口“Ratchet\MessageComponentInterface”]

我正在尝试根据 YouTube 中的教程创建基本的 websocket 聊天,当我运行时,我在终端中遇到此错误

php bin/server.php
Run Code Online (Sandbox Code Playgroud)

致命错误:在第 6 行 /var/www/html/websocket/bin/chat.php 中找不到接口“Ratchet\MessageComponentInterface”

我的 chat.php 代码如下:

<?php
namespace MyApp;
use Ratchet\MessageComponentInterface;
use Ratchet\ConnectionInterface;

class chat implements MessageComponentInterface
    {
        protected $clients;
        public function __construct()
            {
                $this->clients=new \SplObjectStorage;
            }

        public function onOpen(ConnectionInterface $conn)
            {
                $this->clients->attach($conn);
            }

        public function onClose(ConnectionInterface $conn)
            {
                $this->clients->detach($conn);
            }

        public function onMessage(ConnectionInterface $conn,$msg)
            {
                foreach($this->clients as $client){
                    if($client !==$conn){
                        $client->send($msg);
                    }
                }
            }

        public function onError(ConnectionInterface $conn, \Exception $e)
            {
                echo "the following error occured: ".$e->getMessage();
                 $conn->close();
            } …
Run Code Online (Sandbox Code Playgroud)

php websocket ratchet

5
推荐指数
1
解决办法
5948
查看次数

标签 统计

php ×1

ratchet ×1

websocket ×1