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

Phalcon\Cache\Backend\Libmemcached gives "Failed storing data in memcached"

I have web server and memcached server seperately. When i want to Phalcon\Cache\Backend\Libmemcached as model cache, phalcon gives "Failed storing data in memcached"

If I changed to memcached server to 127.0.0.1, it works.

When I test with php memcached library it works.

"telnet remote-memcache-server-ip 11211" works.

How can I detect problem?

PHP version 5.5.24

Phalcon version 1.3.4

php memcached version 2.2.0

libmemcached version 1.0.8



2.9k
Accepted
answer
edited May '15

I think Phalcon\Cache\Backend\Libmemcached use always 127.0.0.1 even if I give another server ip:

$di->set('cache', function () use ($config) {

     $frontCache = new \Phalcon\Cache\Frontend\Data(array(
         "lifetime" => 60*60*10
     ));

     $backend = new \Phalcon\Cache\Backend\Libmemcached($frontCache, [
         "servers" => [
             [
                 "host"   => "remote-ip",
                 "port"   => 11211,
                 "weight" => "1"
             ]
         ]
     ]);

     return $backend;
});

If I start memcached at localhost, Phalcon works but if I stop memcached daemon, Phalcon fails.

Try print_r the backend variable:

$di->set('cache', function () use ($config) {

     $frontCache = new \Phalcon\Cache\Frontend\Data(array(
         "lifetime" => 60*60*10
     ));

     $backend = new \Phalcon\Cache\Backend\Libmemcached($frontCache, [
         "servers" => [
             [
                 "host"   => "remote-ip",
                 "port"   => 11211,
                 "weight" => "1"
             ]
         ]
     ]);

     print_r($backend);
     return $backend;
});

Also, the code could give you some insights: https://github.com/phalcon/cphalcon/blob/2.0.x/phalcon/cache/backend/libmemcached.zep

Here is the print_r output : ( masked my remote memcache ip but writes correct ip )

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

    )

[_options:protected] => Array
    (
        [servers] => Array
            (
                [0] => Array
                    (
                        [host] => *******
                        [port] => 11211
                        [weight] => 1
                    )

            )

        [statsKey] => _PHCM
    )

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

I read "libmemcached.zep" code. My options array seems OK. ( got "servers" key as a array )

edited May '15

I fixed the problem. For model cache, null options param used.

By the way, I clicked accepted answer for wrong post. can we change it?