Pusher和Laravel 5.3事件广播
尝试将Laravel5.3与pusher一起使用,但在我的代码中它似乎工作不正确 我的.env是正确的Pusher和Laravel 5.3事件广播,laravel,events,websocket,pusher,broadcasting,Laravel,Events,Websocket,Pusher,Broadcasting,尝试将Laravel5.3与pusher一起使用,但在我的代码中它似乎工作不正确 我的.env是正确的 PUSHER_APP_ID= myappid PUSHER_KEY= mykey PUSHER_SECRET= mysecret 这是我在broadcasting.php中的“pusher”配置 'pusher' => [ 'driver' => 'pusher', 'key' => env('PUSHER_KEY'),
PUSHER_APP_ID= myappid
PUSHER_KEY= mykey
PUSHER_SECRET= mysecret
这是我在broadcasting.php中的“pusher”配置
'pusher' => [
'driver' => 'pusher',
'key' => env('PUSHER_KEY'),
'secret' => env('PUSHER_SECRET'),
'app_id' => env('PUSHER_APP_ID'),
'options' => [
'cluster' => 'eu',
'encrypted' => true,
],
],
我创建了一个事件,在这里
<?php
namespace App\Events;
use Illuminate\Broadcasting\Channel;
use Illuminate\Queue\SerializesModels;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Broadcasting\PresenceChannel;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
class ProposalEvent implements ShouldBroadcast
{
use InteractsWithSockets, SerializesModels;
public $data;
/**
* Create a new event instance.
*
* @return void
*/
public function __construct($data)
{
$this->data = $data;
}
/**
* Get the channels the event should broadcast on.
*
* @return Channel|array
*/
public function broadcastOn()
{
return ['test-channel'];
// return new PrivateChannel('test-channel');
// return new PresenceChannel('test-channel');
}
}
最后在我看来
event(new App\Events\ProposalEvent('some data'));
不幸的是,这对我不起作用,但当我像这样使用pusher->trigger时,在没有事件的情况下,它工作得很好,我在pusher调试控制台中看到消息
$options = array(
'cluster' => 'eu',
'encrypted' => true
);
$pusher = new Pusher(
'mykey',
'mysecret',
'myid',
$options
);
$data['message'] = 'some data';
$pusher->trigger('test-channel', 'my-event', $data);
我在Laravel文档和其他资源中搜索解决方案。stackoverflow中也有同样的问题,但没有回应。如果有人能帮助我,我将不胜感激,因为我已经好几天找不到解决方案了请尝试通过config/broadcasting.php直接传递推送器凭据
'pusher' => [
'driver' => 'pusher',
'key' => env('PUSHER_KEY'),
'secret' => env('PUSHER_SECRET'),
'app_id' => env('PUSHER_APP_ID'),
'options' => [
'cluster' => 'eu',
'encrypted' => true,
],
],
这对我有用
'default' => 'pusher',
'connections' => [
'pusher' => [
'driver' => 'pusher',
'key' => '***',
'secret' => '**',
'app_id' => '**',
'options' => [
],
],
],
enter code here
我被困在同样的情况下,发现我没有使用队列 在文件中说 在广播事件之前,您还需要配置并运行队列侦听器。所有事件广播都是通过排队作业完成的,因此应用程序的响应时间不会受到严重影响
我之前删除了config/queue.php文件,因为我认为我没有使用它。可能您正在做与我相同的事情,或者队列有问题。在加载页面时,触发视图中的事件是一个错误。首先执行php,然后加载js,这意味着您在js listner显示错误之前使用php触发事件。这可能是第一种情况 第二种情况是你没有下载 如果您确实访问了php.ini并在[curl]中找到了类似于curl的东西 然后右键单击culr文件的路径