message: Failed to connect to Pusher exception: "Illuminate\Broadcasting\BroadcastException" - php

I am using pusher in laravel to send notification but i'm getting following error:
{message: "Failed to connect to Pusher.", exception:
"Illuminate\Broadcasting\BroadcastException",…} exception:
"Illuminate\Broadcasting\BroadcastException" file:
"C:\wamp64\www\notify\vendor\laravel\framework\src\Illuminate\Broadcasting\Broadcasters\PusherBroadcaster.php"
line: 121 message: "Failed to connect to Pusher."
.env:
APP_URL=http://localhost
BROADCAST_DRIVER=pusher
PUSHER_APP_ID=XXX
PUSHER_APP_KEY=XXXX
PUSHER_APP_SECRET=XXX
PUSHER_APP_CLUSTER=ap2
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' => false,
'host' => '127.0.0.1',
'port' => 6001,
'scheme' => 'http',
'curl_options' => [
CURLOPT_SSL_VERIFYHOST => 0,
CURLOPT_SSL_VERIFYPEER => 0,
],
],

Unfortunately, there are several things that might cause this. The one that gets me over and over again, though is that the time on my server is out of sync with the allowance window from Pusher. This happens on one of my VMs when I sleep the laptop.
Check your logs, and check your VM system time. If it is more than a tiny bit out, this could be your issue.
To fix the time issue on a Linux server (and then try again), you can use NTP if you don't have another way:
sudo apt install ntpdate
sudo ntpdate ntp.ubuntu.com
sudo timedatectl set-ntp on
sudo service ntp stop
sudo ntpd -gq
sudo service ntp start

Related

Phpfastcache 6.1.4: Redis is not installed or is misconfigured

phpfastcache v6.1.4 and redis is up running on default port 6379 through Kubernetes.
PHP Fatal error: Uncaught phpFastCache\Exceptions\phpFastCacheDriverCheckException: Redis is not installed or is misconfigured, cannot continue.
Also, please verify the suggested dependencies in composer because as of the V6, 3rd party libraries are no longer required. in /Users/my-path/vendor/phpfastcache/phpfastcache/src/phpFastCache/Drivers/Redis/Driver.php:46
In the config.php.
return [
'driver' => 'redis',
'maxRetries' => 3,
'config' => [
'defaultTtl' => 900,
'host' => 'localhost',
'port' => 6379,
'database' => 11,
'password' => 'some password',
'timeout' => 3,
],
];
So how to setup the Redis config properly?
I answered you on the Github Discussion here.
You either missed the php-redis extension or the php.ini configuration.
However the version 6.1.4 of pfc is no longer supported, I strongly encourage you to upgrade to 8.1 or 9.x.

Laravel beyondcode websockets do not connect

I'm using this Laravel websockets package to have my own websocket server.
As mentioned in package documentation, I have this configuration:
.env setting:
PUSHER_APP_ID=761772
PUSHER_APP_KEY=qwerty
PUSHER_APP_SECRET=secret
PUSHER_APP_CLUSTER=ap2
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' => true,
//'host' => '105.208.174.8', <--I did test this too
'host' => '127.0.0.1',
'port' => 6001,
'scheme' => 'https'//<--Tested with 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:
/**
* Echo exposes an expressive API for subscribing to channels and listening
* for events that are broadcast by Laravel. Echo and event broadcasting
* allows your team to easily build robust real-time web applications.
*/
import Echo from 'laravel-echo'
window.Pusher = require('pusher-js');
window.Echo = new Echo({
broadcaster: 'pusher',
key: 'qwerty',
wsHost: window.location.hostname,
wsPort: 6001,
disableStats: true,
encrypted: true,
enabledTransports: ['ws', 'wss'] //This was added from issue 86
});
This is issue number 86 in package repository
I'm using letsencrypt with my directadmin control panel and this is my SSL part of websockets.php configuration:
'ssl' => [
/*
* Path to local certificate file on filesystem. It must be a PEM encoded file which
* contains your certificate and private key. It can optionally contain the
* certificate chain of issuers. The private key also may be contained
* in a separate file specified by local_pk.
*/
//'local_cert' => null,
'local_cert' => '/home/myDomain/domains/myDomain/public_html/vendor/react/socket/examples/localhost.pem',
//'local_cert' => '/usr/local/directadmin/data/users/myDomain/domains/myDomain.ir.cert',
/*
* Path to local private key file on filesystem in case of separate files for
* certificate (local_cert) and private key.
*/
//'local_pk' => null,
'local_pk' => '/usr/local/directadmin/data/users/myDomain/domains/myDomain.ir.key',
/*
* Passphrase for your local_cert file.
*/
'passphrase' => null,
],
But when I use php artisan websockets:serve, It seems there's something wrong about connection and the myDomain.com/laravel-websockets admin panel says:
Channel's current state is unavailable
and the console says:
Firefox can’t establish a connection to the server at wss://myDomain.ir:6001/app/qwerty?protocol=7&client=js&version=4.3.1&flash=false.
pusher.min.js:8:6335
The connection to wss://myDomain.ir:6001/app/qwerty?protocol=7&client=js&version=4.3.1&flash=false was interrupted while the page was loading.
Does anyone know what's my issue and how should I solve this?
I had the same issue and the problem was the read access of the local_cert and local_pk.
You can use sudo php artisan websocket:serve to try if this is the issue.
If it's the case, add read access to the files or use a user with the access in /etc/supervisor/conf.d/websockets.conf
I had the same problem, I was using Homestead, are you on homestead, if so you should be using supervisor(Debian based) or supervisord (REDHat based) OS to run the laravel socket without manually entering the command "php artisan websockets:serve" at all times.
You can refer to this documentation. https://docs.beyondco.de/laravel-websockets/1.0/basic-usage/starting.html#restricting-the-listening-host
For SSL I also followed this documentation with Valet: https://docs.beyondco.de/laravel-websockets/1.0/basic-usage/ssl.html#usage-with-laravel-valet
I had the same issue first you have to make sure that port you are trying to run is open or not. if you are running socket server on shared hosting then its not possible or you can talk with customer support and they will open port for you. if you have vps or dedicated server you can open port from your control panel. first try to run without ssl if its running fine it means that your port is open then config your ssl config.
If you are using Laravel < 8.0, try composer require pusher/pusher-php-server ^4.1.
my be you have not run server
php artisan websockets:serve
http://127.0.0.1:8000/laravel-websockets
I was struggling with 500 Error till I figured it out
Error message: Attempt to read property "key" on null
authEndpoint: `http://localhost:3060/laravel-websockets/auth`,
auth: {
headers: {
'x-app-id': '**App ID**', // => my issue was HERE
Authorization: 'Bearer jwt TOKEN',
'Access-Control-Allow-Origin': '*'
}
}
and I found it by looking into the file in vendor\beyondcode\laravel-websockets\src\Dashboard\Http\Controllers\AuthenticateDashboard.php
$app = App::findById($request->header('x-app-id'));
$broadcaster = new PusherBroadcaster(new Pusher(
$app->key,
$app->secret,
$app->id,
[]
));
and changed the middlware in App\Providers\BroadcastServiceProvider.php
// from
// Broadcast::routes();
// to
Broadcast::routes(['middleware' => ['auth:api']]);
another change in App\config\websockets.php
'middleware' => [
'api', // => changed it from web to api
Authorize::class,
],
hope this help :)

Elasticache PHP Redis AWS Moved Exception in Laravel

I am using laravel 5.2 and having an architecture of multi-server autoscaling. I want to have session and cache in a centralized location. I want to use AWS elasticache for the same.
I have setup an elasticache Redis cluster having following options :
Parameter group : default.redis.3.2.cluster.on
Shards : 3
Total Nodes : 9
In laravel session configuration I have set redis as the session driver.
In database.php where redis configuration is set, i have used following :
REDIS_HOST=my_aws_elasticache_configuration_endpoint
REDIS_PASSWORD=null
REDIS_PORT=6379
.
When I try to use it, I get following error :
MOVED 13841 some_ip_address_of_aws:6379
I tried using local redis and it worked, so predis is working properly. I tried to check the solutions online, but not able to get the solution. I believe that the configuration endpoint is trying to redirect the redis connection to an available node url out of the 9 nodes I have. However, I have anticipated that AWS should do it internally and not throw exception. Can anyone help me?
I finally got an answer, we need to get the cluster mode on in database settings and set new cluster option to redis. This is how the redis config in database.php looks like :
'redis' => [
'client' => 'predis',
'options' => [
'cluster' => 'redis',
],
'clusters' => [
'default' => [
[
'host' => env('REDIS_HOST', 'localhost'),
'password' => env('REDIS_PASSWORD', null),
'port' => env('REDIS_PORT', 6379),
'database' => 0,
],
],
],
],
If you have password then you can replace options array with this :
'options' => [
'cluster' => 'redis',
'parameters' => ['password' => env('REDIS_PASSWORD', null)],
],

DynamoDB Local - Connection Refused from PHP

I am running DynamoDB Local on port 8080. This is the command used to start the DB:
java -Djava.library.path=./DynamoDBLocal_lib -jar DynamoDBLocal.jar -port 8080
Going to localhost:8080/shell/ yields the DynamoDB Javascript Shell. The shell works and allows operations to be performed on a local db file. The db file created by using the shell is named cUniqueSessionID_us-west-2.db.
In a PHP project, I have the following code for creating a table using DynamoDB
$db = new \Aws\DynamoDb\DynamoDbClient([
'region' => 'us-west-2',
'version' => 'latest',
'endpoint' => 'http://localhost:8080/',
'credentials' => [
'key' => 'not-a-real-key',
'secret' => 'not-a-real-secret',
],
]);
$db->createTable([
'TableName' =>'SampleTable',
'AttributeDefinitions' => [
[ 'AttributeName' => 'Id', 'AttributeType' => 'N' ]
],
'KeySchema' => [
[ 'AttributeName' => 'Id', 'KeyType' => 'HASH' ]
],
'ProvisionedThroughput' => [
'ReadCapacityUnits' => 5,
'WriteCapacityUnits' => 6
]
]);
But running this yields Error executing "CreateTable" on "http://localhost:8080/"; AWS HTTP error: cURL error 7: Failed to connect to localhost port 8080: Connection refused
I've tried turning off my firewall without success. What could be causing this error?
I found the issue.
My PHP project is running in a Vagrant virtual machine, but I was running DynamoDB on my local machine. Thus, the localhost in my PHP code refered to the vagrant localhost but DynamoDB was running on my machine's localhost.
To solve the problem, I ran DynamoDB from within Vagrant.

Install of laravel 4 from pagodabox breaks on localhost

How do I get laravel to work on local host from pagodabox? I've installed laravel 4 through pagoda box, then cloned it to localhost. I then ran composer install to get all the dependencies and updates. When I try to navigate the URI to the public directory, it doesn't show me a "you have arrived" screen. Instead I get the following error message:
A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. [tcp://tunnel.pagodabox.com:6379]
I then looked in "database.php" and noticed that the redis array was modified, so I copied the same one from a fresh installation of Laravel, but then I got the following error:
No connection could be made because the target machine actively refused it. [tcp://127.0.0.1:6379]
I Had the same problem, just change the bootstrap > start.php file, search for
'local' => array('your-machine-name')
and change it with your machine name.
This video help me to deal with that: http://www.youtube.com/watch?v=CJoU-LO8Ufo , in the video he changes it to the virtual host but that didn't work for me, i had to put my computer name.
On Mac the computer name can be found by typing hostname in the terminal.
Joshdcid's answer is right for some, but not all. I found this in my bootstrap > start.php file:
'local' => array('homestead')
..., and changing that variable in any way caused my laravel app to not load at all. Not only that, but in a fresh install of laravel, this local variable had the same value of 'homestead'.
After spending a bit of time in WinMerge, I found that you should use Wayne's tip of changing
'redis' => array(
'cluster' => false,
'default' => array(
'host' => 'tunnel.pagodabox.com',
'port' => 6379,
'database' => 0,
),
),
to
'redis' => array(
'cluster' => false,
'default' => array(
'host' => '127.0.0.1',
'port' => 6379,
'database' => 0,
),
),
at the bottom of the app > config > database.php file, then you should also go to the top of the
app > config > session.php file and change
'driver' => 'redis',
to
'driver' => 'file',
..., just as a fresh install would have. You should be able to view your app now!

Categories