3

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?

3
  • 1
    Are you sure that phpredis session handler gets your new session.gc_maxlifetime? (did you set it in .ini file, or by code, if by .ini , then did you reload configuration, if by code, then do you start session after setting new value) Commented Sep 15, 2016 at 7:27
  • I use ini_set() before the session is started. I'll check out if changing the .ini file acts any different. Commented Sep 15, 2016 at 20:25
  • That did the trick, it's a pity setting it through ini_set() doesn't work, as now I have to make php.ini changes on each of our servers instead of just having the source code do it for me. Commented Sep 15, 2016 at 21:13

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.