Reputation: 1637
I am using PHP 5.5.38 on apache server 2.4.16. I get this problem of losing the session after sometime (around 25 mins). I found these parameters in php.ini file
session.gc_maxlifetime = 1440
session.gc_probability = 10
But in the code these has been setting up to different values. The code looks like this
ini_set('session.gc_maxlifetime', 60*60*24*7);
ini_set('session.use_cookies', 1);
ini_set('session.gc_probability', 0);
and i confirmed them returning the older values which means its not failing or something.
I don't know where else to look to find the cause of losing the session. Any idea or suggestion would be greatly appreciated.
Upvotes: 3
Views: 739
Reputation: 9927
When you set a config value with ini_set()
, it only lasts during the current script execution:
The configuration option will keep this new value during the script's execution, and will be restored at the script's ending.
And, when there are multiple values for session.gc_maxlifetime
, the garbage collector will use the lowest:
If different scripts have different values of session.gc_maxlifetime but share the same place for storing the session data then the script with the minimum value will be cleaning the data.
So what you need to do is either have the ini_set()
assignments in every page where you use sessions, or, the better option, modify directly the php.ini
file to the values you need.
Notice that 25 minutes is aproximately 1440 seconds (24 minutes), so it's definitely using the php.ini
's value.
Upvotes: 1