Greetings.
Faced the problem of killing sessions before their appointed time. That is, I install
ini_set('session.gc_maxlifetime', 120960);
ini_set('session.cookie_lifetime', 120960);
And the session is killed in about 30 minutes.
Google long and carefully. Did not google anything that would help.
I began to read the manual and found the cause of the problem. It turned out all just to stupefy.
The site is hosted on a shared hosting and all sessions are stored in / tmp. Accordingly, the scripts of other sites clean all sessions by the set timeout, which by default is 30 minutes.
So, in order to avoid such a problem, it is necessary to change the storage location of the sessions - that's all.
')
ini_set('session.save_path', $_SERVER['DOCUMENT_ROOT'] .'../sessions/');
As an option, you can. It is important that session files cannot be accessed from outside.
Maybe the information is not new, but since I could not find anything in Google, I decided to post it. Suddenly someone will come in handy.
UPD:The bottom line is that all sessions have a parameter - the beginning. When the script is run - php reads the setting for the lifetime (and the likelihood of launching the garbage collector) and starts the garbage collector. If the garbage collector stumbled upon a session that lived longer than specified in the settings - it is deleted. The session file is deleted, and the user’s cookie, naturally, remains. Accordingly, if any skipt starts with a session time setting of 30 minutes and at the same time it will look for sessions in the same folder where it places another script with a longer time - it will delete ALL sessions, even those that need to live longer. That is why you need to change the folder.
Here is what is written in the official manual on sessions:
“If you’ve been scribing the data. In this case, use this directive together with session.save_path. ”