eithedog eithedog - 1 year ago 73
PHP Question

Memcache - values deleted from memcache reappearing

I'm using memcache to store Zend_Config (and other values) - I'm setting the values as follows:

$memcache = new Memcache();

if (!$config = $memcache->get($memcache->unique_key.APPLICATION_DOMAIN."#config"))
$memcache->set($memcache->unique_key.APPLICATION_DOMAIN."#config", $config);

I'm deleting values as follows:


After I delete the values from memcache, it properly displays in the same connection as deleted - calling
properly gives me
. However, when I refresh the script (and establish new connection with memcache) the data pops back in, as if the memcache state weren't updated. I've tried using
instead (with some specific value), to the same effect - the value doesn't update.

works, and removes everything from memcache, however I want to delete specific keys.

On the manual page there's a cryptic message from 5 years ago about incompatibilities between PECL versions and memcached (but that's from 5 years ago). Can somebody explain to me what might be happening?

I'm using memcached 1.4.21 with memcache (PECL) 3.0.8 on PHP 5.6

Answer Source

The issue stems from usage of this:

$list = array();
$allSlabs = $memcache->getExtendedStats('slabs');

foreach ($allSlabs as $server => $slabs)
    foreach ($slabs as $slabId => $slabMeta)
        foreach ($memcache->getExtendedStats('cachedump', (int) $slabId) as $entries)
            if (!empty($entries))
                foreach ($entries as $key => $entry)
                    if (strpos($key, $memcache->unique_key) === 0)
                        $value = $memcache->get($key);
                        $list[$key] = is_string($value) && unserialize($value) ? unserialize($value) : $value;

(you'll notice that it's not included in my original query, as it doesn't do anything, but lists keys / values stored in memcached)

The problem with this functionality is that it apparently, silently, causes the memcached to become readonly. While the values that are served on consequent calls of the function are updated (as, I think, they're retrieved from local memory), the values in memcached service are not.

This behaviour affects current up-to-date version of memcached - the breaking behaviour was introduced in memcache (2.2.x)

I'll keep bounty open if somebody feels like to investigate this behaviour