我在 Eloquent 事件监听器中使用 Pusher 进行事件广播时遇到问题。我的事件正在从 Laravel Controller 完美地触发和发送。然而,当我从 Eloquent 事件监听器中触发广播时,广播似乎实际上并未到达推送器。
我的 app/Providers/AppServiceProvider.php
的 boot
方法包含:
MyModel::saving(function($record){
doSomeStuf();
// trigger event
$pusher = \App::make('pusher');
$channel = $record->username;
$pusher->trigger($channel, 'status-changed', $record);
doSomeOtherStuf();
return true;
});
当相同的代码放在 Controller 中时,订阅事件的js文件监听事件没有问题。
另请注意,doSomeStuf()
和 doSomeOtherStuf()
执行得非常好,并且没有抛出异常。
最佳答案
结果是日期同步问题。
我的本地服务器是 Ubuntu 机器,而我的实时服务器在 CentOS 上运行。运行以下命令解决了问题:
Ubuntu:
sudo ntpdate ntp.ubuntu.com
CentOS:
sudo ntpdate pool.ntp.org
关于php - Laravel:Pusher 事件不会从 eloquent 的事件监听器中广播,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38692469/