beyondcode / laravel-websockets

Websockets for Laravel. Done right.
https://beyondco.de/docs/laravel-websockets
MIT License
5.07k stars 612 forks source link

"Failed to connect to Pusher." #574

Closed spekulatius closed 3 years ago

spekulatius commented 3 years ago

Hey @rennokki,

after some work with @myckhel I've got the web-sockets mostly working. The frontend connects to the socket server.

One issue remains: The backend application fails to connect to the running web-sockets server (on prod only). The error message is Failed to connect to Pusher.

Tried/Checked:

Configuration

.env

PUSHER_APP_ID=(6-digit number)
PUSHER_APP_KEY=(random alpha-numeric string)
PUSHER_APP_SECRET=(random alpha-numeric string)

MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"

LARAVEL_WEBSOCKETS_SSL_LOCAL_CERT="(path to file, exists)"
LARAVEL_WEBSOCKETS_SSL_LOCAL_PK="(path to file, exists)"

config/broadcasting.php

        'pusher' => [
            'driver' => 'pusher',
            'key' => env('PUSHER_APP_KEY'),
            'secret' => env('PUSHER_APP_SECRET'),
            'app_id' => env('PUSHER_APP_ID'),
            'options' => [
                'cluster' => env('PUSHER_APP_CLUSTER'),
                'useTLS' => true,
                'encrypted' => true,
                'host' => '127.0.0.1',
                'port' => 6001,
                'scheme' => 'http'
            ],
        ],

config/websockets.php

        [
            'id' => env('PUSHER_APP_ID'),
            'name' => env('APP_NAME'),
            'key' => env('PUSHER_APP_KEY'),
            'secret' => env('PUSHER_APP_SECRET'),
            'enable_client_messages' => false,
            'enable_statistics' => true,
        ],

Versions I'm using:

PHP

PHP 7.4.10
laravel/framework                   v7.28.3
beyondcode/laravel-websockets       1.8.1
pusher/pusher-php-server            v4.1.4

Node

pusher-js@^7.0.0
laravel-echo@^1.8.1

Any help is highly appreciated! Have a good weekend!

Cheers, Peter

rennokki commented 3 years ago

If you use 'useTLS' => true,, make sure as well to set 'scheme' => 'https' instead of http

spekulatius commented 3 years ago

Hello @rennokki,

I've tried to set the scheme to https, but it didn't resolve the issue. Any other configuration issues standing out?

Also, would you know where exactly the parameters are passed in? I could check they maybe not passed through correctly.

Thank you! Your help is highly appreciated!

Cheers, Peter

rennokki commented 3 years ago

Downgrade pusher/pusher-php-server to 4.1.3

spekulatius commented 3 years ago

Hey @rennokki, just tried it. The issue is still there, same message - no change.

rennokki commented 3 years ago

This is usually common and can be solved by:

  1. Making sure you set scheme to https and setting up curl_options like below if you set up the paths for SSL certificate & private key.
    'scheme' => 'https',
    'curl_options' => [
    CURLOPT_SSL_VERIFYHOST => 0,
    CURLOPT_SSL_VERIFYPEER => 0,
    ],
  2. Set scheme to http and not use useTLS at all if you are using HTTP (for local testing i.e.)
spekulatius commented 3 years ago

Yaaaay! 🎉️ The curl options fixed it! Thank you so much for your help getting this solved!

NurullahDemirel commented 3 years ago

This is usually common and can be solved by:

  1. Making sure you set scheme to https and setting up curl_options like below if you set up the paths for SSL certificate & private key.
'scheme' => 'https',
'curl_options' => [
    CURLOPT_SSL_VERIFYHOST => 0,
    CURLOPT_SSL_VERIFYPEER => 0,
],
  1. Set scheme to http and not use useTLS at all if you are using HTTP (for local testing i.e.)

where is the setting file ı coulden t find

johanqueo commented 3 years ago

@NurullahDemirel you need to make the changes in the broadcasting.php file