Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting Expire on PHPRedis Sessions

I've got Redis running a shared session storage for several subdomains that I access through PHPRedis. The session cookie has a nice long lifetime so users don't have to log in too often, but I find I have to log in about every half hour anyway.

Examining the Redis instance shows that the TTL for each key is set pretty low by default (about 1500 seconds). The PHPRedis docs have this to say:

Sessions have a lifetime expressed in seconds and stored in the INI variable "session.gc_maxlifetime". You can change it with ini_set().

It's unclear whether this is referring to the cookies lifetime or the TTL of the Redis key. I set both session.cookie_lifetime and session.gc_maxlifetime to 100000 seconds to run a test, but it looks like new session entries still start with the 1500 second TTL in Redis.

It's pretty clear how to set the TTL when interacting with Redis directly, but I don't know how to set this value through PHPRedis' session manager. Any tips?

like image 967
aurath Avatar asked Feb 01 '26 18:02

aurath


1 Answers

kiss-web was right, for whatever reason ini_set('session.gc_maxlifetime', 100000); wasn't working, but changing the setting in php.ini did the trick.

like image 171
aurath Avatar answered Feb 04 '26 09:02

aurath



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!