Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

Cant connect to memcached server error 47

Hi all,

I have memcached running locally and on another server (via vpn), I can successfully communicate with either server from phalcon using the code below:

        $memcache = new Memcached;
        $memcache->addServer('memcache.server.com',11211);  
        echo $memcache->save('trackinglink-50164','http://www.google.com',60;
        echo $memcache->get('trackinglink-50164');

However using Phalcon libmemcached I get:

Uncaught Phalcon\Cache\Exception: Failed storing data in memcached, error code: 47

Here is my service:


$di->set('cache', function () {     
    $frontCache = new FrontData(
        array(
            'lifetime' => 86400,
        )
    );

    $cache = new \Phalcon\Cache\Backend\Libmemcached($frontCache, array(
          "servers" => array(
              array('host' => 'memcache.server.com',
                    'port' => 11211,
                    'weight' => 1),
          ),
          "client" => array(
              Memcached::OPT_HASH => Memcached::HASH_MD5,
              Memcached::OPT_PREFIX_KEY => '',
          )
      ));   

    return $cache;  

})

Here is a print_r of $cache:


     Phalcon\Cache\Backend\Libmemcached Object
(
    [_frontend:protected] => Phalcon\Cache\Frontend\Data Object
        (
            [_frontendOptions:protected] => Array
                (
                    [lifetime] => 86400
                )

        )

    [_options:protected] => Array
        (
            [servers] => Array
                (
                    [0] => Array
                        (
                            [host] => memcache.server.com
                            [port] => 11211
                            [weight] => 1
                        )

                )

            [client] => Array
                (
                    [2] => 1
                    [-1002] => 
                )

            [statsKey] => 
        )

    [_prefix:protected] => 
    [_lastKey:protected] => 
    [_lastLifetime:protected] => 
    [_fresh:protected] => 
    [_started:protected] => 
    [_memcache:protected] => 
)

trying the code below triggers the error:

$cache = Di::getDefault()->getCache();
$cache->save('mydata',array(1,2,3));

I can also telnet to either server, set and get keys just fine.... funny is, code above was working before and all of a sudden I keep getting this error 47 and can no longer do anything....

Can anyone help?



30.5k
Accepted
answer
edited Dec '17

47 means MEMCACHED_SERVER_TEMPORARILY_DISABLED, and you get it when your memcached connection goes into a tcp timeout or passes it's retry limit. It's generated by libmemcached, and is outside your control.

So you need to figure out why your memcached server became (temporarily) inaccessable.

  • 00 = MEMCACHED_SUCCESS
  • 01 = MEMCACHED_FAILURE
  • 02 = MEMCACHED_HOST_LOOKUP_FAILURE (getaddrinfo() and getnameinfo() only)
  • 03 = MEMCACHED_CONNECTION_FAILURE
  • 04 = MEMCACHED_CONNECTION_BIND_FAILURE (Deprecated)
  • 05 = MEMCACHED_WRITE_FAILURE
  • 06 = MEMCACHED_READ_FAILURE
  • 07 = MEMCACHED_UNKNOWN_READ_FAILURE
  • 08 = MEMCACHED_PROTOCOL_ERROR
  • 09 = MEMCACHED_CLIENT_ERROR
  • 10 = MEMCACHED_SERVER_ERROR (Server returns "SERVER_ERROR")
  • 11 = MEMCACHED_ERROR (Server returns "ERROR")
  • 12 = MEMCACHED_DATA_EXISTS
  • 13 = MEMCACHED_DATA_DOES_NOT_EXIST
  • 14 = MEMCACHED_NOTSTORED
  • 15 = MEMCACHED_STORED
  • 16 = MEMCACHED_NOTFOUND
  • 17 = MEMCACHED_MEMORY_ALLOCATION_FAILURE
  • 18 = MEMCACHED_PARTIAL_READ
  • 19 = MEMCACHED_SOME_ERRORS
  • 20 = MEMCACHED_NO_SERVERS
  • 21 = MEMCACHED_END
  • 22 = MEMCACHED_DELETED
  • 23 = MEMCACHED_VALUE
  • 24 = MEMCACHED_STAT
  • 25 = MEMCACHED_ITEM
  • 26 = MEMCACHED_ERRNO
  • 27 = MEMCACHED_FAIL_UNIX_SOCKET (Deprecated)
  • 28 = MEMCACHED_NOT_SUPPORTED
  • 29 = MEMCACHED_NO_KEY_PROVIDED (Deprecated)
  • 30 = MEMCACHED_FETCH_NOTFINISHED
  • 31 = MEMCACHED_TIMEOUT
  • 32 = MEMCACHED_BUFFERED
  • 33 = MEMCACHED_BAD_KEY_PROVIDED
  • 34 = MEMCACHED_INVALID_HOST_PROTOCOL
  • 35 = MEMCACHED_SERVER_MARKED_DEAD
  • 36 = MEMCACHED_UNKNOWN_STAT_KEY
  • 37 = MEMCACHED_E2BIG
  • 38 = MEMCACHED_INVALID_ARGUMENTS
  • 39 = MEMCACHED_KEY_TOO_BIG
  • 40 = MEMCACHED_AUTH_PROBLEM
  • 41 = MEMCACHED_AUTH_FAILURE
  • 42 = MEMCACHED_AUTH_CONTINUE
  • 43 = MEMCACHED_PARSE_ERROR
  • 44 = MEMCACHED_PARSE_USER_ERROR
  • 45 = MEMCACHED_DEPRECATED
  • 46 = MEMCACHED_IN_PROGRESS
  • 47 = MEMCACHED_SERVER_TEMPORARILY_DISABLED
  • 48 = MEMCACHED_SERVER_MEMORY_ALLOCATION_FAILURE
  • 49 = MEMCACHED_MAXIMUM_RETURN (Always add new error code before)

For more see: http://bazaar.launchpad.net/~tangent-trunk/libmemcached/1.0/view/head:/libmemcached-1.0/types/return.h

Thank you for your input!

For some reason, it started working again lol.... I compiled a the latest memcached extension from https://pecl.php.net/package/memcached (3.0.4) and it is now working