PHP Memcache (d) classes: should garbage collection be disabled?

When using the pecc memcached extension (or memcache, which I assume ..), if php session garbage collection (for example: session.gc_probability / session.gc_divisor) is disabled by setting probability 0?

These are stitches, as this may be logical for the following reasons:

A) The expiration time of the session is most likely simply saved by setting the expiration time of the stored key. EG: Each session is given a ttl expiration and is simply cleared by memcached when it expires.

B) In order to clear existing sessions that were not cleared by memcached itself, the memcached extension would have to dump all the data stored in the memcache daemon, check each key to see if the key matches a specific pattern, and then check when the key was added, and finally removed as needed. This is unlikely for the following reasons: 1) As far as I know, you should not indicate when the key was added to memcache. Only when it expires. 2) The dump + syntax would be very difficult for the memcache instance.

Again, is it entirely possible that the memcache (d) pecl extension just disables php session garbage collection?

Thanks.

+4
source share
1 answer

The PHP configuration ini session.gc_maxlifetime determines the expiration of the session record. If you disable this option, your session will be active forever.

If you look at Memcached sources, you can easily determine the behavior (even if you do not understand C): https://github.com/php-memcached-dev/php-memcached/blob/e781e169871fd4f14f844ce3e01860e84ec28831/php_memcached_session.c#L32

The default expiration is set to 0 and is set only if the PHP parameter ini session.gc_maxlifetime set to more than 0. Just because the parameter contains gc does not say that this has anything to do with the PHP session garbage collection . The Memcached extension simply interprets this parameter because it can use it. PHP garbage collection is necessary if you use Memcached, as it will clean itself up and garbage collection will be disabled by the extension itself.

But you still need to set the setting!

+7
source

All Articles