Pusher无法在Laravel 5.8中连接 [英] Pusher fails to connect in Laravel 5.8

查看:192
本文介绍了Pusher无法在Laravel 5.8中连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Laravel 5.4中使用了Pusher,并且没有问题,但是现在我正在尝试使用laravel 5.8,但出现以下错误.我已经尝试了所有可以想到的方法,甚至将encrypted更改为false以防万一.我三重检查了我的推送程序凭据.

Laravel版本5.8

PHP版本7.2.18

OS OSX

我遇到错误

$response = $this->pusher->trigger(
            $this->formatChannels($channels), $event, $payload, $socket, true
        );

        if ((is_array($response) && $response['status'] >= 200 && $response['status'] <= 299)
            || $response === true) {
            return;
        }

        throw new BroadcastException(
            is_bool($response) ? 'Failed to connect to Pusher.' : $response['body']
        );

我的ENV文件

BROADCAST_DRIVER=pusher
PUSHER_APP_ID=XXXXXX
PUSHER_APP_KEY=XXXXXXXXXXXXXXXXXXXX
PUSHER_APP_SECRET=XXXXXXXXXXXXXXXXXXXX
PUSHER_APP_CLUSTER=us2

我的事件文件

<?php

namespace App\Events;

use App\ChatRoomMessage;
use Illuminate\Broadcasting\Channel;
use Illuminate\Queue\SerializesModels;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Broadcasting\PresenceChannel;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;

class NewMessage implements ShouldBroadcast
{
    use Dispatchable, InteractsWithSockets, SerializesModels;


    /**
     * Create a new event instance.
     *
     * @param ChatRoomMessage $chatRoomMessage
     * @return void
     */
    public function __construct()
    {

    }

    /**
     * Get the channels the event should broadcast on.
     *
     * @return \Illuminate\Broadcasting\Channel|array
     */
    public function broadcastOn()
    {
        return new Channel('message');
    }
}

我的路线

Route::get('/broadcast', function() {
    event(new \App\Events\NewMessage);
});

解决方案

在Mac上将Laravel Valet与Php7.2或更高版本结合使用时,如何解决无法连接到Pusher的问题 ————————————————————————————————————————------------ ---

注意:我之所以决定写这篇文章,是因为我认为其他人都不应该花5个小时来解决这个问题,因为我已经做到了.

Server : Valet;

OS: Mac Mojave;

PHP Version: 7.2;

在我的情况下,将forceTLS设置为false是可行的,但是我不喜欢该解决方案.还添加:

'curl_options' => [
  CURLOPT_SSL_VERIFYHOST => 0,
  CURLOPT_SSL_VERIFYPEER => 0,
]

对我的broadcast.php文件有效,但由于某种原因,我也对这种解决方案不满意.

因此,我决定通过从 https://curl下载CA捆绑包来使一切正常. haxx.se/ca/cacert.pem 并将cacert.pem从下载文件夹移至/usr/local/etc/openssl@1.1/certs(在我的情况下,我使用自制软件安装了openssl1.1,因为我试图在网上找到各种东西只是为了使它起作用,但是现在我知道我不需要openssl1.1,您可以使用已经拥有的openssl文件夹),因此cacert文件的完整路径变为/usr/local/etc/openssl@1.1/certs/cacert.pem 打开php.ini ————————

从您的终端输入php --ini以找到加载的php.ini的路径(在您选择的编辑器中打开该路径;有时我使用nano).重要说明:自PHP 7.2(Win 64)起,此指令将不会即使已设置,也要在phpinfo()中显示. (相比之下,如果将opensl.cafile指令设置为完全相同的路径,则会显示该指令.)

因此,现在在您的php.ini中将以下内容设置为:(注意:替换路径以指示可以在系统上找到这些文件的位置)openssl.cafile ="/usr/local/etc/openssl@1.1/certs /cacert.pem'openssl.capath ="/usr/local/etc/openssl@1.1/certs"请注意:因为我使用的是php7.2,所以我不必将curl.cainfo设置为任何值;最初,我花了很多时间尝试使用curl.info方法,但这种方法对我不起作用,因此在我的最终配置中,我在其前面加了分号(; curl.cainfo ="/usr/local/etc /openssl@1.1/certs/cacert.pem")

此后,您应该运行valet restart,这将重新启动某些代客服务,但我意识到即使在代客重新启动后,我执行phpinfo()时,新的php.ini更改也不会反映出来.

最后,您应该通过输入brew服务重启php72来重启php(注意:我是通过自制软件安装的php,所以如果您没有,则必须以不同的方式重启php)

希望这会有所帮助.即使它不能完全解决您的问题,也一定会给您一些想法,就像我在构想我的解决方案时将别人的一小部分想法从一页转移到另一页一样.

I used Pusher with laravel 5.4 and and no issues but now i'm trying to use laravel 5.8 and i get the following error. I've tried everything i can think of and even changed the encrypted to false just incase. I triple checked my pusher credentials.

Laravel Version 5.8

PHP Version 7.2.18

OS OSX

Error I'm getting

$response = $this->pusher->trigger(
            $this->formatChannels($channels), $event, $payload, $socket, true
        );

        if ((is_array($response) && $response['status'] >= 200 && $response['status'] <= 299)
            || $response === true) {
            return;
        }

        throw new BroadcastException(
            is_bool($response) ? 'Failed to connect to Pusher.' : $response['body']
        );

My ENV file

BROADCAST_DRIVER=pusher
PUSHER_APP_ID=XXXXXX
PUSHER_APP_KEY=XXXXXXXXXXXXXXXXXXXX
PUSHER_APP_SECRET=XXXXXXXXXXXXXXXXXXXX
PUSHER_APP_CLUSTER=us2

My Event File

<?php

namespace App\Events;

use App\ChatRoomMessage;
use Illuminate\Broadcasting\Channel;
use Illuminate\Queue\SerializesModels;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Broadcasting\PresenceChannel;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;

class NewMessage implements ShouldBroadcast
{
    use Dispatchable, InteractsWithSockets, SerializesModels;


    /**
     * Create a new event instance.
     *
     * @param ChatRoomMessage $chatRoomMessage
     * @return void
     */
    public function __construct()
    {

    }

    /**
     * Get the channels the event should broadcast on.
     *
     * @return \Illuminate\Broadcasting\Channel|array
     */
    public function broadcastOn()
    {
        return new Channel('message');
    }
}

My route

Route::get('/broadcast', function() {
    event(new \App\Events\NewMessage);
});

解决方案

How to Fix Failed to connect to Pusher when using Laravel Valet with Php7.2 or above On Mac ———————————————————————————————————------------------

NB: I decided to write this because I don’t think anyone else should spend 5 hours fixing this, I have already done that. 


Server : Valet;

OS: Mac Mojave;

PHP Version: 7.2;

In my case turning forceTLS to false worked but I did not like that solution. 
Also adding:

'curl_options' => [
  CURLOPT_SSL_VERIFYHOST => 0,
  CURLOPT_SSL_VERIFYPEER => 0,
]

to my broadcasting.php file worked but for some reason I was not convinced with this solution too. 



So I decided to make things work by downloading the CA bundle from https://curl.haxx.se/ca/cacert.pem and moved the cacert.pem from the downloads folder into /usr/local/etc/openssl@1.1/certs (in my case I installed openssl1.1 using homebrew only because I was trying various things I find online just to make this work but now I know I do not need openssl1.1 you may go with the openssl folder you already have) so the full path to the cacert file becomes /usr/local/etc/openssl@1.1/certs/cacert.pem 

 Opening php.ini 
——————---

From your terminal enter php --ini to find the path to the loaded php.ini (open that in your editor of choice; I use nano sometimes)
Important: As of PHP 7.2 (Win 64) this directive, will NOT show in the phpinfo() even though it's set. (In comparison, an openssl.cafile directive will show, if it's set to the exact same path).

So now in your php.ini set the following to : (NB: replace the path to indicate where those files can be found on your system) 
openssl.cafile = "/usr/local/etc/openssl@1.1/certs/cacert.pem’
openssl.capath = "/usr/local/etc/openssl@1.1/certs"
Take note: because I am using php7.2 I did not have to set curl.cainfo to anything; initially I spent so many hours trying to use curl.info method which did not work for me so in my final configuration I commented it by putting a semi-colon in front of it ( ;curl.cainfo ="/usr/local/etc/openssl@1.1/certs/cacert.pem")

After this you should run valet restart which would restart some valet services but I realised even after valet restarts, my new php.ini changes are not reflecting when I do phpinfo();

Finally you should restart php by entering brew services restart php72 (NB: I installed php via homebrew so incase you did not , you would have to restart php differently)

Hope this helps . Even if it does not solve your problem exactly it would surely give you some ideas to try out just as I leveraged other peoples tiny bits of ideas from one page to another in coming up with my solution.

这篇关于Pusher无法在Laravel 5.8中连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆