Laravel vendor:publish 后棘轮不读取配置文件

Laravel Ratchet not reading config file after vendor:publish

我正在尝试使 Socket 服务器基于 laravel-ratchet

我已完成 git 的安装步骤:

1."composer require askedio/laravel-ratchet"

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

然后我在 app.php 中输入了 class 地址,如下所示:

Askedio\LaravelRatchet\Providers\LaravelRatchetServiceProvider::class,

现在从这个 help 我在应用程序文件夹中创建了我的简单套接字 IoServer class (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);
        }
    }
}

然后我将我的 /config/ratchet.php 更改为:

<?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,
    ],
];

在最后一部分,我将使用 serve 开始我的服务:

php artisan ratchet:serve

它给出了这个错误:

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

我的猜测是,serve 命令正在绕过棘轮配置文件。

如果我试试这个 :

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

错误改为:

Starting IoServer server on: 0.0.0.0:8080

In RatchetServerCommand.php line 155:

  Class 'App\MyRachetSocketServer::class' not found

文件路径正确(下图)。不知道接下来要测试什么?!

我正在使用 Xamp,Vscode,Laravel 5.5。

很久以前我也遇到过同样的问题

试了几次,发现是缓存问题。

尝试使用此命令Package 清除缓存:

php artisan clear:data

或者您可以按顺序使用这些通用命令:

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

最后,按如下方式尝试您的服务器命令:

php artisan ratchet:serve --driver=IoServer

希望对您有所帮助:)