Laravel websockets failed to connect in pusher - php

When I run my project, I got an exception error but it does not have a clear message. I only have this kind of the main body error
I can access websocket admin page at http://127.0.0.1:8000/laravel-websockets but when i go http://127.0.0.1:8000/ i got errors below.
The following error was encountered while trying to retrieve the URL: http://127.0.0.1:6001/apps/995591/events?
Connection to 127.0.0.1 failed.
The system returned: (111) Connection refused
The remote host or network may be down. Please try the request again.
Generated Tue, 05 May 2020 17:12:03 GMT by proxyserversetup-s-1vcpu-1gb-sgp1-07 (squid/3.5.27)
I followed every single thing in the docs from this link
Here are some of my 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'),
'encrypted' => false,
'useTLS' => true,
'host' => '127.0.0.1',
'port' => 6001,
'scheme' => 'http',
'curl_options' => [
CURLOPT_SSL_VERIFYHOST => 0,
CURLOPT_SSL_VERIFYPEER => 0,
],
],
],
.env
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=inventory
DB_USERNAME=root
DB_PASSWORD=
BROADCAST_DRIVER=pusher
PUSHER_APP_ID=995591
PUSHER_APP_KEY=644a4ac1988060882370
PUSHER_APP_SECRET=739696537f4fb23b8fcd
PUSHER_APP_CLUSTER=ap1
I am using laravel 6.x and the current version for laravel websockets.
Is it my ISP cause the error?

I had something similar to this happen to me.
If you are using localhost, change
'useTLS' => true,
to false
'useTLS' => false,
It should be in your broadcasting.php file
'connections' => [
'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' => false,
],
],
....

Making sure you set scheme to https and use 'useTLS' => true then setting up curl_options like below if you set up the paths for SSL certificate & private key.
'curl_options' => [
CURLOPT_SSL_VERIFYHOST => 0,
CURLOPT_SSL_VERIFYPEER => 0,
],

Verify the PUSHER_PORT data in the .env file:
PUSHER_HOST=127.0.0.1
PUSHER_PORT=6379
Verify using CLI in the docroot with artisan command for web socket:
php artisan websockets:serve --port=6379

Related

Laravel WebSockets cannot send event

I'm having troubles with dispatching events on my local Laravel configuration.
I'm trying to dispach it directly from the dashboard http://localhost:8000/laravel-websockets, but it always return Error sending event. Even if it is connecting to the dashboard.
My config looks:
.env file:
QUEUE_CONNECTION=database
QUEUE_DRIVER=sync
BROADCAST_DRIVER=pusher
PUSHER_APP_ID=local
PUSHER_APP_KEY=local
PUSHER_APP_SECRET=local
PUSHER_APP_CLUSTER=mt1
PUSHER_PORT=6001
PUSHER_SCHEME=http
PUSHER_HOST=127.0.0.1
Configuration in boradcasting.php:
'pusher' => [
'driver' => 'pusher',
'key' => env('PUSHER_APP_KEY'),
'secret' => env('PUSHER_APP_SECRET'),
'app_id' => env('PUSHER_APP_ID'),
'options' => [
'host' => env('PUSHER_HOST', 'api-'.env('PUSHER_APP_CLUSTER', 'mt1').'.pusher.com') ?: 'api-'.env('PUSHER_APP_CLUSTER', 'mt1').'.pusher.com',
'port' => env('PUSHER_PORT', 443),
'scheme' => env('PUSHER_SCHEME', 'https'),
'encrypted' => true,
'useTLS' => env('PUSHER_SCHEME', 'https') === 'https',
],
Configuration in websockets.php:
'apps' => [ [
'id' => env('PUSHER_APP_ID'),
'name' => env('APP_NAME'),
'key' => env('PUSHER_APP_KEY'),
'secret' => env('PUSHER_APP_SECRET'),
'path' => env('PUSHER_APP_PATH'),
'capacity' => null,
'enable_client_messages' => false,
'enable_statistics' => true,
],
],
I did enable all providers, and still not dispatching even from the dashboard.
I tried to create event and dispatch from the controller, but still not working.
Any ideas what could cause it?
Edit: just noticed in dashboard a message like:
Channels current state is connected

Laravel websockets AWS EC2 - Connection failed

I'm using laravel-websockets and is working like a charm in my local docker machine but I can't seem to make it work when I deploy it in the AWS EC2 machine.
This is the error message I get:
pusher.min.js:8 WebSocket connection to
'wss://sample.project:6001/app/b0901feacd04936e?protocol=7&client=js&version=4.3.1&flash=false' failed:
These are my config files:
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'),
'host' => '127.0.0.1',
'port' => 6001,
'scheme' => 'http',
],
],
websockets.php
'apps' => [
[
'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,
],
],
bootstrap.js
window.Echo = new Echo({
broadcaster: 'pusher',
key: process.env.MIX_PUSHER_APP_KEY,
cluster: process.env.MIX_PUSHER_APP_CLUSTER,
wsHost: window.location.hostname,
wsPort: 6001,
forceTLS: false,
disableStats: true,
});
I've opened 6001 port in my security group:
But I can't make it work. I've tried a lot of the fixes in other SO questions but none worked, am I missing something? In desperate need of help here.
Thank you very much.
Your SSL settings in config/websockets.php should indicate they require two variables fron the .env file.
'ssl' => [
'local_cert' => env('LARAVEL_WEBSOCKETS_SSL_LOCAL_CERT', null),
'local_pk' => env('LARAVEL_WEBSOCKETS_SSL_LOCAL_PK', null),
'passphrase' => null,
'verify_peer' => false,
],
Then over in your .env file, for local (in Valet) specify your test site's certs, ie:
LARAVEL_WEBSOCKETS_SSL_LOCAL_CERT="/users/grant/.config/valet/Certificates/localsite.test.crt"
LARAVEL_WEBSOCKETS_SSL_LOCAL_PK="/users/grant/.config/valet/Certificates/localsite.test.key"
Alternatively, if it's on your Production environment, point it to your production SSL CRT & key:
LARAVEL_WEBSOCKETS_SSL_LOCAL_CERT="/etc/nginx/ssl/yourprodsite.com/1231342/server.crt"
LARAVEL_WEBSOCKETS_SSL_LOCAL_PK="/etc/nginx/ssl/yourprodsite.com/1231342/server.key"
Your bootstrap.js (or similar) receiving JS end wouldn't really change - just ensure it matches what's in config/broadcasting.php:
import Echo from 'laravel-echo';
window.Echo = new Echo({
broadcaster: 'pusher',
key: 'yoursite-pusher-key',
wsHost: window.location.hostname,
wsPort: 6001,
wssPort: 6001,
disableStats: true,
});
Config counterpart config/broadcasting.php inside of the connections array:
'pusher' => [
'driver' => 'pusher',
'key' => 'yoursite-pusher-key',
'secret' => 'yoursite-secret',
'app_id' => 'yoursite',
'options' => [
'cluster' => 'main-cluster',
'encrypted' => true,
'host' => '127.0.0.1',
'port' => 6001,
'scheme' => 'https',
'curl_options' => [
CURLOPT_SSL_VERIFYHOST => 0,
CURLOPT_SSL_VERIFYPEER => 0,
]
],
],
Personally I could not get my setup to work without SSL & had to provide the SSL certificates accurately. Don't forget to use valet secure locally, if using Valet.
You can have a look here for more info regarding SSL.
Once you serve the Websockets using php artisan websockets:serve it's OK if it seems like it's stalling, navigate over to the frontend & hard refresh (CMD+SHIFT+R) or Win (CTRL+F5) and hopefully the connection will be established.
Ensure you are using latest libraries and if you have set up your JavaScript init scripts inside of a bootstrap you may need to run npm run dev or similar to compile assets.

Laravel Redis - artisan cache:clear - Connection refused [unix:/path/.redis/redis.sock]

 I have configured Redis (using a socket) in the Laravel in my hosting server. Everything works fine (I have tested reading from cache, sessions etc.), I have one database for a cache and a second one for users sessions.
 However, when I run "php artisan cache:clear" it shows the error:
"In AbstractConnection.php line 155: Connection refused [unix:/path/.redis/redis.sock]".
This error also occures when I run any command which uses Redis, for example "php73 artisan cron:updateForeignPrices".
.env
CACHE_DRIVER=redis
SESSION_DRIVER=redis
REDIS_HOST=/path/.redis/redis.sock
REDIS_PASSWORD=null
REDIS_PORT=0
REDIS_CACHE_DB=0
REDIS_SESSION_DB=1
config/database.php
'redis' => [
'client' => env('REDIS_CLIENT', 'predis'),
'cluster' => true,
'options' => [
'cluster' => env('REDIS_CLUSTER', 'predis'),
'prefix' => Str::slug(env('APP_NAME'), '_').'_',
'parameters' => ['password' => env('REDIS_PASSWORD', null)],
],
'default' => [
'scheme' => 'unix',
'path' => env('REDIS_HOST'),
'host' => env('REDIS_HOST'),
'password' => env('REDIS_PASSWORD'),
'port' => env('REDIS_PORT'),
'database' => env('REDIS_CACHE_DB', 0)
],
'cache' => [
'scheme' => 'unix',
'path' => env('REDIS_HOST'),
'host' => env('REDIS_HOST'),
'password' => env('REDIS_PASSWORD'),
'port' => env('REDIS_PORT'),
'database' => env('REDIS_CACHE_DB', 0),
],
'session' => [
'scheme' => 'unix',
'path' => env('REDIS_HOST'),
'host' => env('REDIS_HOST'),
'password' => env('REDIS_PASSWORD'),
'port' => env('REDIS_PORT'),
'database' => env('REDIS_SESSION_DB', 1),
]
]
Hosting provider's info about Redis (translated):
Socket: /path-to-my-directory/.redis/redis.sock
User and password: (none)
Port: 0
RAM: 128 MB
Instruction on WordPress Litespeed:
In the „Host” field paste address from the panel, for example: /home/klient.dhosting.pl/dhtutorial/.redis/redis.sock
In the „Port” field remove a default value and type "0".
Leave "user" and "password" empty.
 It seems like everything works correctly in a direct use of Redis, but not via console. Anyone has an idea how to fix it?
Thanks in advance, I have searched whole Internet.
REDIS_HOST should point to the address where the Redis server is hosted whether it's hosted on a local machine or cloud service. somethings like below:
REDIS_HOST=12.0.0.1
REDIS_PASSWORD=password
REDIS_PORT=6379
set REDIS_HOST=127.0.0.1 or your host address
Try to use the following configuration.
.env
CACHE_DRIVER=redis
SESSION_DRIVER=redis
REDIS_SCHEME=unix
REDIS_PATH=/path/.redis/redis.sock
REDIS_CACHE_DB=0
REDIS_SESSION_DB=1
config.database.php
'redis' => [
'client' => env('REDIS_CLIENT', 'predis'),
'cluster' => true,
'options' => [
'cluster' => env('REDIS_CLUSTER', 'predis'),
'prefix' => Str::slug(env('APP_NAME'), '_').'_',
'parameters' => ['password' => null],
],
'default' => [
'scheme' => env('REDIS_SCHEME'),
'path' => env('REDIS_PATH'),
'database' => env('REDIS_CACHE_DB', 0)
],
'cache' => [
'scheme' => env('REDIS_SCHEME'),
'path' => env('REDIS_PATH'),
'database' => env('REDIS_CACHE_DB', 0),
],
'session' => [
'scheme' => env('REDIS_SCHEME'),
'path' => env('REDIS_PATH'),
'database' => env('REDIS_SESSION_DB', 1),
]
]

Laravel WebSockets: Illuminate \ Broadcasting \ BroadcastException: No Message and net::ERR_CERT_AUTHORITY_INVALID

I've been trying to get this WebSocket package running on my local Laravel project for about a week now and I can't seem to find a solution to the issue. I've followed the documentation, multiple tutorials and answers on Stack Overflow / Github, but I keep getting the same error. These are my configurations:
.env:
PUSHER_APP_ID=anyId
PUSHER_APP_KEY=anyKey
PUSHER_APP_SECRET=anySecret
PUSHER_APP_CLUSTER=eu
config/broadcasting:
'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' => false,
'host' => '127.0.0.1',
'port' => 6001,
'scheme' => 'http',
'curl_options' => [
CURLOPT_SSL_VERIFYHOST => 0,
CURLOPT_SSL_VERIFYPEER => 0,
]
],
]
config/websockets:
'apps' => [
[
'id' => env('PUSHER_APP_ID'),
'name' => env('APP_NAME'),
'key' => env('PUSHER_APP_KEY'),
'secret' => env('PUSHER_APP_SECRET'),
'path' => env('PUSHER_APP_PATH'),
'capacity' => null,
'enable_client_messages' => false,
'enable_statistics' => true,
],
],
resources/js/bootstrap.js:
There is also WebsocketEvent and controller which calls the broadcasting of the event, I haven't included them to keep this shorter.
import Echo from 'laravel-echo'
window.Pusher = require('pusher-js');
window.Echo = new Echo({
broadcaster: 'pusher',
key: 'anyKey',
encrypted: false,
wsHost: window.location.hostname,
wsPort: 6001,
disableStats: true,
enabledTransports: ['ws', 'wss']
});
window.Echo.channel('DemoChannel')
.listen('WebsocketEvent', (e) => {
console.log(e);
});
Front-end error: This only seems to be fine when I set enabledTransports: ['wss'] which represents the secure connection but default of enabledTransports: ['ws'] doesn't.
Back-end error: Always fails.
As you can see, I've added the curl options as recommended on https://github.com/beyondcode/laravel-websockets/issues/109 and I've set encrypted: false. Overall, I believe it is a certificate issue which is beyond my full comprehension but the tutorials I followed seem to get it working perfectly on their local environment without SSL certificates, etc. Also, it seems like other developers who are having similar issues are not getting answered (example), which is why I am posting this. Any help would be appreciated, thank you.

WebSocket connection to 'wss://127.0.0.1/app/anyKey?protocol=7&client=js&version=6.0.3&flash=false' failed. how to fix this laravel websocket error

broadcasting.php my sample. i don't know how to fix it
If you know the answer please help me
'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'),
'encrypted' => false,
'host' => '127.0.0.1',
'port' => 6001,
'scheme' => 'http',
],
],
Error Photo click Here

Categories