Sessions in Laravel 5.0 keep piling up - laravel-5

I have set sessions to be stored in the database. just one user is logged in and after a couple of minutes 700+ sessions are stored. the system uses a lot of ajax calls, but that shouldn't be causing this.
This is how session.php looks like:
return [
'driver' => env('SESSION_DRIVER', 'database'),
'lifetime' => 1200,
'expire_on_close' => true,
'encrypt' => false,
'files' => storage_path().'/framework/sessions',
'connection' => null,
'table' => 'sessions',
'lottery' => [2, 100],
'cookie' => 'laravel_session',
'path' => '/',
'domain' => null,
'secure' => false,
];
Anybody have a clue?

Related

Integration laravel 7 log to slack

I tried to integration error log laravel to slack notification. But when i tested to send log it can't send massage to slack. I followed this tutorial https://panjeh.medium.com/send-laravel-6-log-to-slack-notification-573a6d95a14e. And I've tested on route too
Here is it the config.php
'channels' => [
'stack' => [
'driver' => 'stack',
'channels' => ['single','slack'],
'ignore_exceptions' => false,
],
'single' => [
'driver' => 'single',
'path' => storage_path('logs/laravel.log'),
'level' => 'debug',
],
'daily' => [
'driver' => 'daily',
'path' => storage_path('logs/laravel.log'),
'level' => 'debug',
'days' => 14,
],
'slack' => [
'driver' => 'slack',
'url' => env('LOG_SLACK_WEBHOOK_URL'),
'username' => 'Laravel Log',
'emoji' => ':boom:',
'level' => 'warning',
],
Here is it the route to test
Route::get('slack', function() {
Log::error('Test');
return 'Slack notif';
});
I've got the url too and have it put in .env LOG_SLACK_WEBHOOK_URL=
You can change default log channels to slack.So you have to set
LOG_CHANNEL=stack
Also you can specify channels. Instead of changing channels
Log::channel('slack')->inf("test");
or you can do
Log::stack(['daily', 'slack'])->info("test");
or you can specify channels inside daily array.So that no need to change anythink
'stack' => [
'driver' => 'stack',
'channels' => ['daily', 'slack'],
'ignore_exceptions' => false,
],

Laravel (phpredis) will not connect with password (AWS Elasticache)

I have a Redis 6.x instance on AWS Elasticache. It is clustered, and has in-transit encryption. I also have a RBAC set up (User with a password in AWS). I am able to connect using the redis-cli and then authorize using AUTH <password> and it works great. (It uses Redis 6 ACL feature)
However when I add the password to my Laravel configuration I get the error:
Couldn't map cluster keyspace using any provided seed
If I remove the password from the User in Elasticache, Laravel connects fine and uses Redis perfectly.
Here is my configuration. The password is correct in my env file and because of clustering, is added both in default connection and in the options['parameters'] key.
'redis' => [
'client' => 'phpredis',
'cluster' => true,
'clusters' => [
'default' => [
[
'scheme' => 'tls',
'host' => env('REDIS_HOST', '127.0.0.1'),
'password' => env('REDIS_PASSWORD', null),
'port' => env('REDIS_PORT', 6379),
'database' => 0,
],
],
'options' => [
'cluster' => 'redis',
],
],
'options' => [
'parameters' => [
'scheme' => 'tls',
'password' => env('REDIS_PASSWORD', null),
],
'ssl' => ['verify_peer' => false],
'context' => [],
],
],
I've seen this error before but it seems like it occurs whenever something bad happens, rather than giving me specifics. For example, if I remove the password, and restrict some of the access permissions like SET or READ/WRITE commands, then I also get the same error, and so it is very hard to decipher what the error is.
Are you using Laravel 5 or 6?
Our setup is similar to yours, but this solution only seems to work with Laravel 6, but when I use this same configuration, I get the same issue as you in Laravel 5.
'redis' => [
'client' => 'phpredis',
'cluster' => true,
'options' => [
'cluster' => 'redis',
'ssl' => ['verify_peer' => false],
'context' => [],
'password' => env('REDIS_PASSWORD', null),
'parameters' => [
'scheme' => env('REDIS_SCHEME', 'tls'),
],
],
'clusters' => [
'default' =>
[
[
'host' => env('REDIS_HOST', 'localhost'),
'password' => env('REDIS_PASSWORD', null),
'port' => env('REDIS_PORT', 6379),
'database' => env('REDIS_DATABASE', 0),
'persistent' => true,
],
],
'options' => [
'cluster' => 'redis',
]
],
],
Now to figure out how to make my Laravel 5 app work, (Or I'll just have to upgrade my Laravel Apps).

Laravel's "logout other devices" feature not working

I'm using Laravel 6.0.4. I was asked to logout users from all devices whenever they log in from a new location. Supposedly, Laravel makes this very easy with this:
https://laracasts.com/series/whats-new-in-laravel-5-6/episodes/7
public function logoutOtherDevices($password, $attribute = 'password'){ ... }
I can see that the code changes the password hash in the database, but the user is still logged in. So it must be that somewhere in the code I am failing to check that the hash has changed. I'm not an expert, perhaps this is an issue related to guards? Our system has four guards. Could it be that some of the guards are not being authenticated correctly? That the guard is not using the hash from the database but some other system?
So, how do I figure out why Laravel isn't logging people out from other devices? I will share config data if you want, just ask me which data to post
Auth.php
'defaults' => [
'guard' => 'web',
'passwords' => 'users',
],
'guards' => [
'web' => [
'driver' => 'session',
'provider' => 'users',
],
'staff' => [
'driver' => 'session',
'provider' => 'staff'
],
'partner' => [
'driver' => 'session',
'provider' => 'partner'
],
'api' => [
'driver' => 'token',
'provider' => 'users',
'hash' => false,
],
],
'providers' => [
'partner' => [
'driver' => 'eloquent',
'model' => \App\Models\Partner::class,
],
'staff' => [
'driver' => 'eloquent',
'model' => \App\Models\Staff::class
],
'users' => [
'driver' => 'database',
'table' => 'users',
],
],
'passwords' => [
'users' => [
'provider' => 'users',
'table' => 'password_resets',
'expire' => 60,
],
'partner' => [
'provider' => 'partner',
'table' => 'password_resets',
'expire' => 60,
],
'staff' => [
'provider' => 'staff',
'table' => 'password_resets',
'expire' => 60,
]
],
session.php
'driver' => env('SESSION_DRIVER', 'file'),
'lifetime' => env('SESSION_LIFETIME', 120),
'expire_on_close' => false,
'encrypt' => false,
'files' => storage_path('framework/sessions'),
'connection' => env('SESSION_CONNECTION', null),
'table' => 'sessions',
'store' => env('SESSION_STORE', null),
'lottery' => [2, 100],
'cookie' => env(
'SESSION_COOKIE',
Str::slug(env('APP_NAME', 'laravel'), '_').'_session'
),
'path' => '/',
'domain' => env('SESSION_DOMAIN', null),
'secure' => env('SESSION_SECURE_COOKIE', false),
'http_only' => true,
'same_site' => null,

How do I configure the session in my cakephp application?

Im trying create a endpoint for a session to my application. I follow all the steps in https://book.cakephp.org/3.0/en/development/sessions.html
But dont works.
I create the table im my database called session and the ComboSession in src/Http/Session/ComboSession.php and change the conigurations in app.php like the documentation of cakephp suggests.
'Session' => [
'defaults' => 'database',
'handler' => [
'engine' => 'ComboSession',
'model' => 'session',
'cache' => 'apc'
]
],
'Cache' => [
'apc' => ['engine' => 'Apc']
]
I tried this too:
'Cache' => [
'apc' => ['engine' => 'Apcu']
]
My error message: Cache engine Cake\Cache\Engine\ApcuEngine is not properly configured.
My souluction:
'Session' => [
'defaults' => 'database',
'handler' => [
'engine' => 'ComboSession',
'model' => 'sessions',
'cache' => 'defaults'
]
],
'Cache' => [
'defaults' => [
'className' => 'Cake\Cache\Engine\FileEngine',
'path' => CACHE,
'url' => env('CACHE_DEFAULT_URL', null),
],

Laravel horizon remains inactive after a new deploy

We have Horizon running for quite some time now, and have no issues with it.
But after our most recent deploy on production, it remains inactive and there are no workers being started.
I fail to see the problem, nor do we get any errors logged into bugsnag, so I'm a bit lost here.
What would be the best way to debug issues with Horizon? I have verified, and I can talk to redis. The dashboard also displays jobs on the queue, so it's just a matter of the workers not being started.
We're setting up our instances using Laravel forge, and I can confirm that there is a daemon that runs php artisan horizon in the correct directory. Running that command manually on the server also doesn't give me much info that I can work with.
I'm sure here must be SOME error, but it's not beig caught / displayed / whatever. Any thoughts on how to properly debug this?
This is the contents of config/horizon.php:
<?php
return [
'use' => 'default',
'waits' => [
'redis:default' => 60,
],
'environments' => [
'dev' => [
'all-prio' => [
'connection' => 'redis',
'queue' => ['default', 'high', 'medium', 'low'],
'balance' => 'auto',
'processes' => 10,
'tries' => 3,
],
],
'acc' => [
'all-prio' => [
'connection' => 'redis',
'queue' => ['default', 'high', 'medium', 'low'],
'balance' => 'auto',
'processes' => 10,
'tries' => 3,
],
],
'production' => [
'high-prio' => [
'connection' => 'redis',
'queue' => ['high'],
'balance' => 'auto',
'processes' => 10,
'tries' => 5,
],
'default-prio' => [
'connection' => 'redis',
'queue' => ['medium', 'default'],
'balance' => 'auto',
'processes' => 10,
'tries' => 3,
],
'low-prio' => [
'connection' => 'redis',
'queue' => ['low'],
'balance' => 'auto',
'processes' => 5,
'tries' => 3,
],
],
],
];
The environment is correctly being set to 'production' on that environment.
This is the contents of the config/database.php redis section:
'redis' => [
'cluster' => false,
'default' => [
'host' => env('REDIS_HOST', 'localhost'),
'password' => env('REDIS_PASSWORD', null),
'port' => env('REDIS_PORT', 6379),
'database' => 0,
]

Resources