When using the pecl memcached (or memcache I guess..) extension, should php's session garbage collection (eg: session.gc_probability / session.gc_divisor) be disabled by setting the probability to 0?
It seams as tho this might be logical for the following reasons:
A) Session expiry time is most likely simply stored by setting the expiry time on the stored key. EG: Each session is given its expiry ttl, and simply purged by memcached when it expires.
B) To flush out existing sessions that have not been purged by memcached itself, the memcached extension would have to do a full dump of all the data that is stored in the memcache daemon, check each key to see if the key matches the defined pattern, and then check when the key was added, and finally remove as necessary. This is unlikely for the following reasons: 1) As far as I know, there is no to tell when a key was added to memcache. Only when it expires. 2) The dump + parse would be super heavy on memcache instance.
Then again, its quite possible that the memcache(d) pecl extension simply disables php's session garbage collection?
Thanks.
The PHP ini setting session.gc_maxlifetime
defines the expiration of a session entry. If you disable this option your session will be active forever.
If you have a look at the Memcached sources it’s easy to spot the behavior (even if you don’t understand C): https://github.com/php-memcached-dev/php-memcached/blob/e781e169871fd4f14f844ce3e01860e84ec28831/php_memcached_session.c#L325-L327
The expiration is set to 0 by default and only set if the PHP ini setting session.gc_maxlifetime
is set to something greater than 0. Just because the setting contains a gc
doesn’t say that this has something to do with PHPs session garbage collection. The Memcached extension simply interprets this option as it can utilize it. No PHP garbage collection is necessary if you use Memcached, as it will clean itself and the garbage collection is disabled by the extension itself.
But you still have to set the setting!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With