Fusio api cache configuration - php

Googled and tried,but failed.
How to configure Fusio to use redis.?
//'psx_cache_factory' => null,
This doesnt work:
'psx_cache_factory' => 'redis'
This also doesnt work:
'psx_cache_factory' => 'redis://127.0.0.1:6379',

Answered by developer.
Github
'psx_cache_factory' => function($config, $namespace){
$client = new \Predis\Client([
'scheme' => 'tcp',
'host' => '10.0.0.1',
'port' => 6379,
]);
return new \Doctrine\Common\Cache\PredisCache($client);
},

Related

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),
]
]

How to move file to other server in Laravel using ftp and private key?

i want to move file from my site to other server using ftp in laravel.
i put this setting in config/filesystem.php and its works
'ftp' => [
'driver' => 'ftp',
'host' => 'ftp.xxx.my',
'username' => 'xxx',
'password' => 'xxx',
'root' => '/tess',
],
But my client ask to use private key only without password and username, so i changed my setting
'ftp' => [
'driver' => 'ftp',
'host' => 'ftp.xxx.my',
'privateKey' =>storage_path('app/public/key/momuat.ppk'),
'root' => '/tess',
],
and i got error
Could not login with username: anonymous, host: 192.168.0.123
Please help me

Laravel + Redis Cache via SSL?

I am trying to connect to Redis with predis 1.1 and SSL, using information https://github.com/nrk/predis, where in the example the following configuration is used:
// Named array of connection parameters:
$client = new Predis\Client([
'scheme' => 'tls',
'ssl' => ['cafile' => 'private.pem', 'verify_peer' => true],
]);
My Laravel configuration looks like below:
'redis' => [
'client' => 'predis',
'cluster' => env('REDIS_CLUSTER', false),
'default' => [
'host' => env('REDIS_HOST', 'localhost'),
'password' => env('REDIS_PASSWORD', null),
'port' => env('REDIS_PORT', 6379),
'database' => 0,
],
'options' => [
'cluster' => 'redis',
'parameters' => ['password' => env('REDIS_PASSWORD', null)],
'scheme' => 'tls',
],
],
Unfortunately I am getting the following error:
ConnectionException in AbstractConnection.php line 155:
Error while reading line from the server. [tcp://MY_REDIS_SERVER_URL:6380]
Suggestions are appreciated :)
I was able to get it to work!
You need to move 'scheme' from 'options' to 'default':
My working config:
'redis' => [
'client' => 'predis',
'cluster' => env('REDIS_CLUSTER', false),
'default' => [
'scheme' => 'tls',
'host' => env('REDIS_HOST', 'localhost'),
'password' => env('REDIS_PASSWORD', null),
'port' => env('REDIS_PORT', 6379),
'database' => 0,
],
'options' => [
'parameters' => ['password' => env('REDIS_PASSWORD', null)],
],
],
Note: I had also removed the 'cluster' option from 'options', but I don't suspect this to be the make-or-break with this problem.
In my final-final config, I changed it to: 'scheme' => env('REDIS_SCHEME', 'tcp'), and then defined REDIS_SCHEME=tls in my env file instead.
Tested with AWS ElastiCache with TLS enabled.
Edit:
The above config only works with single-node redis. If you happen to enable clustering and TLS then you'll need a different config entirely.
'redis' => [
'client' => 'predis',
'cluster' => env('REDIS_CLUSTER', false),
// Note! for single redis nodes, the default is defined here.
// keeping it here for clusters will actually prevent the cluster config
// from being used, it'll assume single node only.
//'default' => [
// ...
//],
// #pro-tip, you can use the Cluster config even for single instances!
'clusters' => [
'default' => [
[
'scheme' => env('REDIS_SCHEME', 'tcp'),
'host' => env('REDIS_HOST', 'localhost'),
'password' => env('REDIS_PASSWORD', null),
'port' => env('REDIS_PORT', 6379),
'database' => env('REDIS_DATABASE', 0),
],
],
'options' => [ // Clustering specific options
'cluster' => 'redis', // This tells Redis Client lib to follow redirects (from cluster)
]
],
'options' => [
'parameters' => [ // Parameters provide defaults for the Connection Factory
'password' => env('REDIS_PASSWORD', null), // Redirects need PW for the other nodes
'scheme' => env('REDIS_SCHEME', 'tcp'), // Redirects also must match scheme
],
]
]
Explaining the above:
'client' => 'predis': This specifies the PHP Library Redis driver to use (predis).
'cluster' => 'redis': This tells Predis to assume server-side clustering. Which just means "follow redirects" (e.g. -MOVED responses). When running with a cluster, a node will respond with a -MOVED to the node that you must ask for a specific key.
If you don't have this enabled with Redis Clusters, Laravel will throw a -MOVED exception 1/n times, n being the number of nodes in Redis cluster (it'll get lucky and ask the right node every once in awhile)
'clusters' => [...] : Specifies a list of nodes, but setting just a 'default' and pointing it to the AWS 'Configuration endpoint' will let it find any/all other nodes dynamically (recommended for Elasticache, because you don't know when nodes are comin' or goin').
'options': For Laravel, can be specified at the top-level, cluster-level, and node option. (they get combined in Illuminate before being passed off to Predis)
'parameters': These 'override' the default connection settings/assumptions that Predis uses for new connections. Since we set them explicitly for the 'default' connection, these aren't used. But for a cluster setup, they are critical. A 'master' node may send back a redirect (-MOVED) and unless the parameters are set for password and scheme it'll assume defaults, and that new connection to the new node will fail.
Thank you CenterOrbit!!
I can confirm the first solution does allow Laravel to connect to a Redis server over TLS. Tested with Redis 3.2.6 on AWS ElastiCache with TLS, configured as single node and single shard.
I can also confirm the second solution does allow Laravel to connect to a Redis Cluster over TLS. Tested with Redis 3.2.6 on AWS ElastiCache with TLS, configured with "Cluster Mode Enabled", 1 shard, 1 replica per shard.
I was receiving the following error when I first tried to implement the cluster solution:
Error: Unsupported operand types
I missed the additional set of array brackets when I moved the "default" settings into the "clusters" array.
INCORRECT
'clusters' => [
'default' => [
'scheme' ...
]
]
CORRECT
'clusters' => [
'default' => [
[
'scheme' ...
]
]
]
I hope this saves someone else a bit of troubleshooting time.
The accepted solution by CenterOrbit worked for me, as I was using AWS I had to add tls:// in my .env
Laravel
tls://username:password#URL:PORT?database=0
Try it. It will work

Send Email from SMTP remote server CakePHP 3

I'm facing some problems configuring my app to send Mails from my smtp server, which is located in one remote hosting with 1and1.
I don't know if I'm missing something:
I've changed my app.php to the values given by my hosting provider:
'EmailTransport' => [
'default' => [
'className' => 'Mail',
'host' => 'smtp.1and1.com',
'port' =>'587' ,
'timeout' => 30,
'username' => 'me#dns.com',
'password' => '******',
'client' => null,
'tls' => null,
],
],
'Email' => [
'default' => [
'transport' => 'default',
'from' => '#localhost',
//'charset' => 'utf-8',
//'headerCharset' => 'utf-8',
],
],
Here you can see the instructions given by my hosting provider to connect to their smtp server.
I don't get any result.
Does anybody have an Idea what may I be missing?
I got it working setting classname as 'Mail' and the rest of the parameters as default. Please, do as follows:
'EmailTransport' => [
'default' => [
'className' => 'Mail',
// The following keys are used in SMTP transports
'host' => 'localhost',
'port' => 25,
'timeout' => 30,
'username' => 'user',
'password' => 'secret',
'client' => null,
],
],
In my case only was problem in className.
For using gmail or office365 server it should be so:
'EmailTransport' => [
'default' => [
'className' => 'Mail',
// The following keys are used in SMTP transports
'host' => 'smtp.office365.com',
'port' => 587,
'timeout' => 30,
'username' => 'my#email.com',
'password' => 'myPassword',
'client' => null,
'tls' => true,
'url' => env('EMAIL_TRANSPORT_DEFAULT_URL', null),
],
],
Please do as following:
//Adding Smtp information for sending mail through smtp instead of php mail function on local server / live server
'EmailTransport' => [
'default' => [
'className' => 'Smtp',
'host' => 'smtp.1and1.com',
'port' =>'587' ,
'timeout' => 30,
'username' => 'me#dns.com',
'password' => '******',
'client' => null,
'tls' => null,
],
],
You can also enable tls to 'tls' => true if required.

Laravel Redis Error - Cannot use SAVE with a cluster of connections

I am new in Redis. Is anyone know, why these error showing?
I am using Laravel.
Cannot use SAVE with a cluster of connections
Cannot use FLUSHDB with a cluster of connections
$redis = Redis::connection();
$redis->set('name', 'Harry');
echo $name = $redis->get('name'); //It is working fine
$redis->save();
www/projectname/app/config/database.php
Find,
'redis' => array(
'cluster' => false,
'default' => array(
'host' => '127.0.0.1',
'port' => 6379,
'database' => 0,
)
);
If ‘cluster’ is true, make it false. May be your issue will solve.

Categories