We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Memcached, always get error code: 47

Hi all,
I'm experiencing a strange behaviour of the memcached adapter. While I try to save a value I always receive an error: Failed storing data in memcached, error code: 47.
But if i try to connect to memcached container through telnet or by php, it works correctly.
When I use the cache adapter for saving values it always get an error. This is my cache dump:

Phalcon\Cache\Multiple Object ( [_backends:protected] => Array ( [0] => Phalcon\Cache\Backend\Libmemcached Object ( [_frontend:protected] => Phalcon\Cache\Frontend\Data Object ( [_frontendOptions:protected] => Array ( [lifetime] => 86400 ) ) [_options:protected] => Array ( [servers] => Array ( [0] => Array ( [prefix] => cache [host] => memcached [port] => 11211 ) ) [statsKey] => ) [_prefix:protected] => [_lastKey:protected] => [_lastLifetime:protected] => [_fresh:protected] => [_started:protected] => [_memcache:protected] => ) [1] => Extended\ExtendedCache Object ( [cacheServiceIsAvailable:protected] => 1 [_frontend:protected] => Phalcon\Cache\Frontend\Data Object ( [_frontendOptions:protected] => Array ( [lifetime] => 604800 ) ) [_options:protected] => Array ( [prefix] => [cacheDir] => /var/www/BraveNewSystem/cache/cache/frontend/weekendinitaly/ ) [_prefix:protected] => [_lastKey:protected] => [_lastLifetime:protected] => [_fresh:protected] => [_started:protected] => [_useSafeKey:Phalcon\Cache\Backend\File:private] => ) ) )    

Failed storing data in memcached, error code: 47  
#0 [internal function]: Phalcon\Cache\Backend\Libmemcached->save('navigation-en-p...', Array, 3000, NULL)

This is a sample php code working without errors on same server:

<?php  
$ip = "memcached";
$port= 11211;

$memcache = new Memcache;
$memcache->connect($ip,$port);

$memcache->set('rule_1', 'You DO NOT talk about FIGHT CLUB');
echo $memcache->get('rule_1');

47 means MEMCACHED_SERVER_TEMPORARILY_DISABLED

You need to install memcache or/and run memcache server.

source

Good luck



12.1k

But the server is installed, running and working. I can use it everywhere except phalcon

are you rigth the adapter is Libmemcached ? in your code say Memcache



12.1k
edited Mar '18

Memcache is a php module for memcached, but it works also with memcached module, like the next example

$mem_var = new Memcached();
$mem_var->addServer("memcached", 11211);
$response = $mem_var->get("Bilbo");
if ($response) {
    echo $response;
} else {
    echo "Adding Keys (K) for Values (V), You can then grab Value (V) for your Key (K) \m/ (-_-) \m/ ";
    $mem_var->set("Bilbo", "Here s Your (Ring) Master stored in MemCached (^_^)") or die(" Keys Couldn't be Created : Bilbo Not Found :'( ");
}

Store that ring by 60 years in Bilbo's pocket

I think i also ran into that problem with that library , so I just set up regular memcched as a shared service in the di.


/**
* Set up Memcached
*/
$di->set('cache', function()  {
    $config = $this->getConfig();
    $memcached = new \Memcached();
    $memcached->addServer('localhost', 11211);
    $memcached->setOption(Memcached::OPT_PREFIX_KEY, "test");
    return $memcached;
});

$this->cache->set($key, $data, $cacheTime);


12.1k

Trent it is a solution, but it doesn't work inside the Multiple cache frontend.