Ratchet Fatal Error: Class 'Myapp Chat' not found in C: wamp www bin chat-server.php

Asked

Viewed 386 times

0

I’m trying to learn how to use the new Html5 API, Websocket, and I decided to start testing Ratchet, which is a php library. Anyway, I followed all the steps of this tutorial to create a basic chat http://socketo.me/docs/hello-world and when running on the terminal it does not find the Chat.php. class. The file structure is like this:

bin
   chat-server.php
src
   MyApp
      Chat.php
vendor
   autoload.php
   (...)
composer.json
composer.lock

My files are like this:

Composer.json

{
  "autoload": {
    "psr-0": {
        "MyApp": "src"
    }
 },
 "require": {
    "cboden/ratchet": "0.3.*"
 }
}

chat-server.php

<?php
use Ratchet\Server\IoServer;
use MyApp\Chat;

require dirname(__DIR__) . '/vendor/autoload.php';

$server = IoServer::factory(
    new Chat(),
    8080
);

$server->run();

Chat.php

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

class Chat implements MessageComponentInterface {
    public function onOpen(ConnectionInterface $conn) {
    }
    public function onMessage(ConnectionInterface $from, $msg) {
    }
    public function onClose(ConnectionInterface $conn) {
    }
    public function onError(ConnectionInterface $conn, \Exception $e) {
    }
}

ps: I found on forums some similar issues, but no procedure solved

  • 1

    Installed the dependencies of the package? composer install. If not, I recommend reading this here: http://br.phptherightway.com/

  • yes, I installed, uninstalled and installed again to ensure and nothing

1 answer

1

I was with the same problem, but I managed to solve it as follows, after doing all that you did, enter again in the folder of your project via terminal and run: composer update after that run the server with the command also in the terminal php bin/chat-server.php

  • 1

    THANK YOU VERY MUCH! I had even given up, but your answer helped me and made it work, thank you very much

Browser other questions tagged

You are not signed in. Login or sign up in order to post.