Search code examples
phpmemcachedtokyo-cabinet

Tokyo Cabinet cluster and PHP (via memcache)


I have 2 servers running tokyo cabinet in a cluster (2 hard drives so 4 instances of Tokyo Cabinet). if it's just one instance of tokyo cabinet it's fairly straight forward to use php memcache protocol to communicate. My question is how do you connect php if it's cluster?

Option 1: $memcache->connect('memcache_host', 11211); Using this option you can only connect to on instance of tokyo cabinet.

Option 2: $memcache = new Memcache; $memcache->addServer('memcache_host', 11211); $memcache->addServer('memcache_host2', 11211); Using this, you can connect to multiple, but are the data stored correctly in the cluster?

Thank you!


Solution

  • Use option 2 and let the client library do its thing. You can rest assured that you data will be distributed to all the memcached instances in the pool.

    You could take a look at PHP Memcached library (notice the D at the end), it has some nice features you can take advantage of (it has a different algorithm for distributing data which you might find useful).