Sockets not working in AWS ec2 using PHP? - php

Unable to make socket.io working on AWS EC2
https://mydoamin.com:2120/socket.io/?EIO=3&transport=polling&t=NQpMyRI net::ERR_TIMED_OUT
i.create # socket.io.js?v=1609310849:7
Localhost everything working fine the way it should be working but on live environment, I am getting above error.
When I connect using [workerman][1] and starting it using CLI on was ubuntu instance it is working fine
Somehow ports are not working properly even I have added it in security groups under inbound settings:-
And now this error after configuring:
<?php
use kriss\webMsgSender\WebMsgSender;
return [
'components' => [
// others
WebMsgSender::COMPONENT_NAME => [
'class' => WebMsgSender::class,
'pushApiClientHost' => '0.0.0.0',
'logCategory' => 'webMsgSender',
],
],
];
New error
socket.io.js?v=1609310849:7 GET https://myDoamin.com:2120/socket.io/?EIO=3&transport=polling&t=NQpU3PA net::ERR_CONNECTION_RESET
Extension I am using

Make sure you configure socket io to listen to be bonded to all IP addresses, not just the localhost
so instead of
<?php
use kriss\webMsgSender\WebMsgSender;
return [
'components' => [
// others
WebMsgSender::COMPONENT_NAME => [
'class' => WebMsgSender::class,
'pushApiClientHost' => 'localhost',
'logCategory' => 'webMsgSender',
],
],
];
change to
<?php
use kriss\webMsgSender\WebMsgSender;
return [
'components' => [
// others
WebMsgSender::COMPONENT_NAME => [
'class' => WebMsgSender::class,
'pushApiClientHost' => '0.0.0.0',
'logCategory' => 'webMsgSender',
],
],
];
basically change localhost to 0.0.0.0

Related

Unexpected error communicating with Stripe. If this problem persists, let us know at support#stripe.com. (Network error [errno 26])

I am working on xampp, windows 10
$account = \Stripe\Account::create([
'country' => 'US',
'type' => 'custom',
'requested_capabilities' => ['card_payments', 'transfers'],
]);
$file = \Stripe\File::create([
'purpose' => 'identity_document',
'file' => fopen('../images/3.jpg', 'r'),
], [
'stripe_account' => 'acct_xxx',
]);
$verification = \Stripe\Account::update(
'acct_xxxxx',
[
'company' => [
'verification' => [
'document' => [
'front' => $file->id,
],
],
],
]
);
When running it gives me the following error:
Unexpected error communicating with Stripe. If this problem persists, let us know at support#stripe.com. (Network error [errno 26]: )
I tried updating TLS version, I unchecked 1.0 and 1.0 and just kept 1.2 enabled but it didn't help.
You should run the Stripe reachability tool from the same machine to ensure you're able to communicate with the API.
If this is an intermittent error you can also configure automatic retries, though idempotency keys are recommended in this case.

Is there any php function that wait untill aws lightsail instance state is running?

I have used this code to create aws lightsail instance using php code.
$client->createInstances([
'addOns' => [
[
'addOnType' => 'AutoSnapshot',
'autoSnapshotAddOnRequest' => [
'snapshotTimeOfDay' => config('aws.snapshotTime'),
],
],
],
'availabilityZone' => config('aws.instanceAvailabilityZone'),
'blueprintId' => config('aws.os'),
'bundleId' => config('aws.instanceType'),
'instanceNames' => ['testinstance],
'userData' => config('aws.afterInstallScript'),
]);
return $result = $client->getInstanceState([
'instanceName' => $instanceName
]);
The code is executed with instance state pending. But my requirement is that it should return when the instance state is running. Aws SDK has waitUntil() function but I don't know how to use this in lightsail.
Can anyone help me with this?

Exception: Illuminate \ Broadcasting \ BroadcastException No message in PusherBroadcaster.php:119

Laravel 5.8
I am new to this whole pusher functionality and I've been following this tutorial and trying it out,
Create Web Notifications Using Laravel and Pusher Channels.
I've followed it step-by-step and when I get to the step to manually test the event by visiting the test url, I receive the following exception:
Illuminate \ Broadcasting \ BroadcastException
No message
C:\wamp\www\ares\vendor\laravel\framework\src\Illuminate\Broadcasting\Broadcasters\PusherBroadcaster.php
Here is the code:
$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( // <-- Exception at this line
is_bool($response) ? 'Failed to connect to Pusher.' : $response['body']
);
}
/**
* Get the Pusher SDK instance.
*
* #return \Pusher\Pusher
*/
public function getPusher()
{
return $this->pusher;
}
}
I've looked at a few other stack overflow articles which talk about changing encrypted: true to encrypted: false but that does not seem to affect anything.
I started working on Laravel 4 days ago and I came across this same problem when I was implementing a real-time chat application. After searching for many days, I discovered that this may vary depending on the version of Laravel you are running. If it is 5.8, you can fix this by adding the following code in the pusher.options array of the file config/broadcasting.php:
'curl_options' => [
CURLOPT_SSL_VERIFYHOST => 0,
CURLOPT_SSL_VERIFYPEER => 0,
],
After adding this , your pusher array in the config/broadcasting.php should look like this.
'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,
'curl_options' => [
CURLOPT_SSL_VERIFYHOST => 0,
CURLOPT_SSL_VERIFYPEER => 0,
],
],
],
You can then run php artisan config:cache(which may not be necessary in some cases) and finally run php artisan serve.You can consult your app in the pusher website and see the events you receive after sending your messages.
Hope it helps!!
If you're working on localhost try setting your .env file.
Set:
APP_URL=http://localhost
DB_HOST=localhost
And run
php artisan config:cache
Like i mentioned in a comment before this happens when the whole post goes wrong and wont deliver a response. Thats why the exception in line 116 is raised. I changed it to the domain before!
In my case i followed the code an found the method "createPusherDriver" in "vendor/laravel/framework/src/Illuminate/Broadcasting/BroadcastManager.php". At this place i inserted this
var_dump($config['key']);
var_dump($config['secret']);
var_dump( $config['app_id']);
var_dump($config['options']);
exit;
an noticed that my options still listed "host" => "localhost".
I removed those lines an cleared the config cache by executing php artisan config:cache
On next reload my event was fired an logged in the console.
Worked perfectly up to my Laravel 5.8 version. But encrypted' => true or encrypted' => false did not matter in this case for such Laravel version. But, following PUSHER suggestions, I put to broadcasting: 'useTLS' => true,.
This is the final result to me:
'options' => [
'cluster' => env('PUSHER_APP_CLUSTER'),
'encrypted' => true,
'useTLS' => true,
'curl_options' => [
CURLOPT_SSL_VERIFYHOST => 0,
CURLOPT_SSL_VERIFYPEER => 0,
],
]
Thanks to dear #Bitart
'useTLS' => true
option solved my issue.
'options' => [
'cluster' => env('PUSHER_APP_CLUSTER'),
'useTLS' => true,
]

Pull down AWS S3 bucket locally in Laravel

I have a task of pulling down assets which are stored on an AWS S3 bucket and storing those in a local project using Laravel. Also, the files are encrypted.
I need to write a script to do this.
Any ideas on how to do this?
Assuming you have following disks :
'disks' => [
'local' => [
'driver' => 'local',
'root' => storage_path('app'),
],
's3' => [
'driver' => 's3',
'key' => env('S3_KEY'),
'secret' => env('S3_SECRET'),
'region' => env('S3_REGION'),
'bucket' => env('S3_BUCKET'),
'http' => [
'connect_timeout' => 30,
],
],
],
Then you can copy file using :
if(Storage::disk('s3')->exists('path/yourfile.txt')){
Storage::disk('local')->writeStream('path/yourfile.txt', Storage::disk('s3')->readStream('path/yourfile.txt'));
}
To move the file :
if(Storage::disk('s3')->exists('path/yourfile.txt')){
Storage::disk('local')->writeStream('path/yourfile.txt', Storage::disk('s3')->readStream('path/yourfile.txt'));
Storage::disk('s3')->delete('path/yourfile.txt');
}
If you have set default disk then you can skip mentioning it spefically and directly do Storage::something()
Moving all files from s3 to local disk :
Considering you have different disks which are not on the same server, you need to do little bit extra as compared to both disks on the same server :
$s3Files = Storage::disk('s3')->allFiles();
foreach ($s3Files as $file) {
// copy
Storage::disk('local')->writeStream($file, Storage::disk('s3')->readStream($file));
// move
Storage::disk('local')->writeStream($file, Storage::disk('s3')->readStream($file));
Storage::disk('s3')->delete($file);
}
Or You can move the delete() after the entire moving and delete all files together like :
Storage::disk('s3')->delete(Storage::disk('s3')->allFiles());
which is essentially similar but just one function call.

Digital Ocean spaces not working in the remote environment - Laravel 5.5

I used this tutorial to define a driver and connect to my spaces on Digital Ocean.
In my config\filesystems.php I have this code:
'spaces' => [
'driver' => 'spaces',
'version' => '2006-03-01',
'key' => env('DO_SPACES_KEY'),
'secret' => env('DO_SPACES_SECRET'),
'endpoint' => env('DO_SPACES_ENDPOINT'),
'region' => env('DO_SPACES_REGION'),
'bucket' => env('DO_SPACES_BUCKET'),
'bucket_name' => env('DO_SPACES_BUCKET'),
],
In one of my controllers iI have this code:
$client->subdomain = 'acme';
$directories_client = Storage::disk('spaces')->directories('clients/'.$client->subdomain);
Problem
The connection to spaces driver works perfectly in my local environment.
However, in remote environment, this line
$directories_client = Storage::disk('spaces')->directories('clients/'.$client->subdomain);
produces error. Here is hat my log says:
[2017-09-29 07:19:08] remote.ERROR: Driver [] is not supported.
{"userId":5,"email":"_________","exception":"[object]
(InvalidArgumentException(code: 0): Driver [] is not supported. at
/.../src/Illuminate/ Filesystem/FilesystemManager.php:124)
The local code works perfectly at the very same time as the remote fails.
Any ideas?
Peter
you need use s3 as driver name, just change this
'driver' => 'spaces', to 'driver' => 's3',

Categories