Friday, September 2, 2011


This issue bothers me today. My environment is ubuntu 10.10 + PHP5.3. Both memcached and php5-memcached are installed correctly, and memcached service is running properly.

Here is my testing code, copied from PHP manual:

//first part, testing Memcache
$memcache_obj = new Memcache;$memcache_obj->connect('localhost'11211);
$memcache_obj->set('var_key''some really big variable'MEMCACHE_COMPRESSED5000);

//second part, testing Memcached
$m = new Memcached();$m->addServer('localhost'11211);
$m->set('int'99);$m->set('string''a simple string');$m->set('array', array(1112));


The result is quite confusing me: the first part, testing Memcache, works very well. But the second part, testing Memcached doesn't work! Instead, the result message is WRITE FAILURE, the result code is Memcached::RES_WRITE_FAILURE.

As usual, the message doesn't help much in debugging. I google this issue, but cannot find any helpful solution. I even removed memcached(I installed them using sudo apt-get install) and then download the packages and install them manually(./configure, make, make install). But still cannot solve the problem. And i almost think probably it is a ubuntu bug and i have to upgrade my ubuntu(PHP manual explains Memcached::RES_WRITE_FAILURE means 'Failed to write network data').

At last, i just 'accidently' change Memcached 'localhost' to, and it turns out that this accident solves the problem! But what i still get confused with is why Memcahe can use 'localhost' while Memcached have to use ''. Shouldn't be either they both must use 'localhost' or they both have to use ''?

1 comment:

Francis Varga said...

haha i have the same problem on my EC2 and i have try already everything and nothing works! annoying BUT local works everything fine xD