Laravel: Pusher events do not broadcast from within eloquent's event listener

旧巷老猫 提交于 2019-12-03 18:11:27

问题


I'm having issues doing event broadcasting using Pusher from within an Eloquent event listener. My event are being fired and sent out from Laravel controller perfectly. However, it seems that the broadcasts are not actually reaching pusher when I trigger them from within my Eloquent event listener.

The boot method of my app/Providers/AppServiceProvider.php contains:

MyModel::saving(function($record){
    doSomeStuf();

    // trigger event
    $pusher = \App::make('pusher');
    $channel = $record->username;
    $pusher->trigger($channel, 'status-changed', $record);

    doSomeOtherStuf();

    return true;
});

The js file that subscribes to the event has no problem listening to the event when the same code is placed in a controller.

Also note that doSomeStuf() and doSomeOtherStuf() are executed quite fine and no exception is thrown.


回答1:


Turned out to be a date synchronization issue.

My local server is an Ubuntu machine while my live server is running on CentOS. Running the following commands solved the problem:

Ubuntu:

sudo ntpdate ntp.ubuntu.com

CentOS:

sudo ntpdate pool.ntp.org



来源:https://stackoverflow.com/questions/38692469/laravel-pusher-events-do-not-broadcast-from-within-eloquents-event-listener

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!