Search code examples
phplaravelratchet

Laravel Ratchet not reading config file after vendor:publish


Im trying to make Socket server base on laravel-ratchet.

ive done installation steps from git :

1."composer require askedio/laravel-ratchet"

2. "$ php artisan vendor:publish --provider="Askedio\LaravelRatchet\Providers\LaravelRatchetServiceProvider"

then ive entered class address in app.php like this :

Askedio\LaravelRatchet\Providers\LaravelRatchetServiceProvider::class,

now from this help ive created my simple socket IoServer class in app folder (App/MyRatchetSocketServer):

<?php

namespace App;


use Ratchet\ConnectionInterface;
use Askedio\LaravelRatchet\RatchetServer;

class MyRatchetSocketServer extends RatchetServer
{
    public function onMessage(ConnectionInterface $conn, $input)
    {
        parent::onMessage($conn, $input);

        if (!$this->throttled) {
            $this->send($conn, 'Hello you.');

            $this->sendAll('Hello everyone.');

            $this->send($conn, 'Wait, I don\'t know you! Bye bye!');

            $this->abort($conn);
        }
    }
}

then ive changed my /config/ratchet.php to this :

<?php

return [
    'class'           => \App\MyRatchetSocketServer::class,
    'host'            => '127.0.0.1',
    'port'            => '8989',
    'connectionLimit' => false,
    'throttle'        => [
        'onOpen'    => '5:1',
        'onMessage' => '20:1',
     ],
    'abortOnMessageThrottle' => false,
    'blackList'              => [],
    'zmq'                    => [
        'host'   => '127.0.0.1',
        'port'   => 5555,
        'method' => \ZMQ::SOCKET_PULL,
    ],
];

and in final part im going to start my service with serve :

php artisan ratchet:serve

and it gives this error :

Starting WampServer server on: 0.0.0.0:8080

In RatchetServerCommand.php line 204:

  Askedio\LaravelRatchet\Examples\Pusher must be an instance of Askedio\LaravelRatchet\RatchetWampServer to create a Wamp server

my guess is that , serve command is bypassing the ratchet config file.

also if i try this :

php artisan ratchet:serve --driver=IoServer --class="App\MyRachetSocketServer::class"

the error changed to this :

Starting IoServer server on: 0.0.0.0:8080

In RatchetServerCommand.php line 155:

  Class 'App\MyRachetSocketServer::class' not found

the file path is correct (bottom pic). dont know what to test next ?!

enter image description here

Im using Xamp , Vscode , Laravel 5.5.


Solution

  • I had the same problem long time ago

    after a few try , find out that it was a cache problem.

    try this Package for clearing cache with this command :

    php artisan clear:data
    

    or u can use these generic command in order:

    php artisan cache:clear
    php artisan view:clear
    php artisan route:clear
    php artisan clear-compiled
    php artisan config:cache
    

    and finaly , try your server command as follows :

    php artisan ratchet:serve --driver=IoServer
    

    hope that helps :)