You should include your composer dependencies first in server.php.
<?php
require __DIR__ . '/vendor/autoload.php'; // this one on top
require 'core/Chat.php';
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I want to use Ratchet web socket in my project and when i tray to connect it i face this problem and i tray to update and dump the composer but it dose not work ! any one who can help me please ? here is my composer.json file
{
"autoload": {
"psr-4": {
"MyChatApp\": "src"
}
},
"require": {
"cboden/ratchet": "^0.4.1"
}
}
my server.php file
<?php
require 'core/Chat.php';
require __DIR__ . '/vendor/autoload.php';
use Ratchet\Server\IoServer;
use MyApp\Chat;
use Ratchet\Http\HttpServer;
use Ratchet\WebSocket\WsServer;
$server = IoServer::factory(
new HttpServer(
new WsServer(
new Chat()
)
),
8081
);$server->run();
my chat.php file
<?php
namespace MyChatApp;
use Ratchet\MessageComponentInterface;
use Ratchet\ConnectionInterface;
class Chat implements MessageComponentInterface
{ protected $clients;
public function __construct() {
$this->clients = new \SplObjectStorage;
}
public function onOpen(ConnectionInterface $conn)
{
// Store the new connection to send messages to later
$this->clients->attach($conn);
echo "New connection! ({$conn->resourceId})\n";
}
public function onMessage(ConnectionInterface $from, $msg)
{
$numRecv = count($this->clients) - 1;
echo sprintf('Connection %d sending message "%s" to %d other connection%s' . "\n",
$from->resourceId, $msg, $numRecv, $numRecv == 1 ? '' : 's');
foreach ($this->clients as $client) {
if ($from !== $client) {
//The sender is not the receiver, send to other clients
$client->send($msg);
}
}
}
public function onClose(ConnectionInterface $conn)
{
// The connection is closed, remove from connection list
$this->clients->detach($conn);
echo "Connection {$conn->resourceId} has disconnected\n";
}
public function onError(ConnectionInterface $conn, \Exception $e)
{
echo "An error has occurred: {$e->getMessage()}\n";
$conn->close();
}
}
and the error is "Fatal error: Interface 'Ratchet\MessageComponentInterface' not found in C"
Please or to participate in this conversation.