我正在尝试使套接字服务器基于laravel-ratchet。
从git完成的安装步骤:
1."composer require askedio/laravel-ratchet"
2. "$ php artisan vendor:publish --provider="Askedio\LaravelRatchet\Providers\LaravelRatchetServiceProvider"
然后我在 app.php 中输入课程地址,如下所示:
Askedio\LaravelRatchet\Providers\LaravelRatchetServiceProvider::class,
现在从这个help我在应用程序文件夹( App / MyRatchetSocketServer )中创建了我的简单套接字 IoServer 类:
<?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,
],
];
最后一部分,我将以服务开始我的服务:
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。
答案 0 :(得分:1)
很久以前我也遇到过同样的问题
尝试几次后,发现这是缓存问题。
尝试使用此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
希望有帮助:)