我正在尝试用beyondcode的laravel-websockets和pusher-php-server来制作实时的laravel应用程序,但是我没有指定pusher/pusher-php-server
包的版本,因为它需要一个过时的php版本。
我创建了“NewTrade”事件实现了“ShouldBroadcastNow”然后我通过tinker运行以下命令触发了该事件:
event (new \App\Events\NewTrade('test'))
它会传回:
>>> event (new \App\Events\NewTrade('test'));
=> [
null,
]
已激发NewTrade事件的“broadcastOn”方法
public function broadcastOn()
{
$test = new \App\Models\Test();
$test->title = "event";
$test->save();
return new Channel('trades');
}
我在数据库中看到了这个,测试表中正在创建新记录。但是在websockets Jmeter 板(http://127.0.0.1:8000/laravel-websockets)中没有关于这个事件的信息。
我做错了什么?
2条答案
按热度按时间0qx6xfy61#
我没有指定pusher/pusher-php-server软件包的版本,因为它需要一个过时的php版本。
我犯了同样的错误,结果在这个问题上挣扎了几个小时。
很显然,the latest version of
pusher-php-server
is not compatible withlaravel-websockets
。github用户mankms发布的以下解决方案为我修复了这个问题:
mspsb9vt2#
可能您没有正确配置应用程序(.env文件)。
这里是官方的laravel-websockets文档https://beyondco.de/docs/laravel-websockets/getting-started/introduction
有关广播和websockets的Laravel文档,您可以查看https://laravel.com/docs/9.x/broadcasting#introduction
你跑了没有:
?
此外,我正在努力与Laravel Sail(Docker)设置这个包,最终切换到Soketi,而不是因为任何原因,事件从来没有被抓住,就像你有问题。所以最有可能你的问题是配置相关。