ini_set('session.gc_probability',1); ini_set('session.gc_divisor',1);
These two commands force PHP to run a script session cleanup for EVERY hit on your site. PHP formula to run gc:
if (random() < (gc_probability / gc_divisor)) then run_session_garbage_collector() }
You now have 1/1, so there is a 100% chance that the garbage collector will start. Although extending the waiting period is good, you also want to REDUCE the chance that the collector works at all. Otherwise, you force PHP to perform a full scan of ALL session files and parse EACH one, for EVERY hit on your site, to find an odd one or two that might have expired.
Try setting gc_probability to 0 to completely disable the garbage collector.
Also, remember that changing the settings, like you, inside the script using ini_set (), does not change the timeouts / defaults used by OTHER scripts. This script may have a longer timeout and change the likelihood, but if other scripts exceed the default timeout (10 minutes or something else), then they will be happy to make any "obsolete" sessions.
The right place to set the timeout / session cleanup parameters is at the php.ini level, so it applies to all the scripts on the site, and not just to your one script.
source share