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

[need help please] I want to store session data in multiple memcache server.

Hello, Im trying store session in multiple memcache server, why session only store data in one of memcache server ? but if I'm comment one of them, it works.


$driver_session = new \Phalcon\Session\Adapter\Libmemcached(array(
        'servers' => array(
                 /*array(
                     'host' => '192.168.0.105', // mandatory
                    'port' => 11211, // optional (standard: 11211)
                     'weight' => 8600, // optional (standard: 8600)
                 ),*/
                 array(
                     'host' => '192.168.0.101', // mandatory
                     'port' => 11211, // optional (standard: 11211)
                     'weight' => 8600, // optional (standard: 8600)
                 )
             ),
             'client' => array(
                 Memcached::OPT_HASH => Memcached::HASH_MD5,
                 Memcached::OPT_PREFIX_KEY => 'prefix.',
             ),
             'lifetime' => 3600,
             'prefix' => 'ini_session_')
         );

 $driver_sesion->start();


2.1k

https://github.com/phalcon/cphalcon/blob/2.0.0/phalcon/session/adapter/libmemcached.zep

It only accept server as a single entry

https://github.com/phalcon/cphalcon/blob/2.0.0/phalcon/session/adapter/libmemcached.zep#L103

In order for you to use multiple server, you need to extend the class, and rewrite it.

//change this to an array let this->_libmemcached = new Libmemcached( new FrontendData(["lifetime": this->_lifetime]), ["servers": servers, "client": client, "prefix": prefix, "statsKey": statsKey] );

and change the read,write,destroy as well to be a for loop and handle multiple server