Strange return codes from PHP memcache set functions

Anthony Volodkin anthonyv at
Sat Nov 18 03:19:27 UTC 2006


For the future readers of this list:

It seems that the issue I ran into can happen if you try to store a 0 
(as a value) using PHP/memcached.

The 0 will get stored correctly, however, several things may happen upon your attempt to retrieve this 0:

- The memcache client may attempt to failover (if enabled+using multiple 
servers) onto another server (potentially causing subsequent memcache accesses to fail)

- Because a 0 is also "false" error-detecting code (a simple "or" example 
below) will be triggered making it difficult to tell if you really received a 0 or whether 
something failed.

So there, hopefully will save someone some debugging. :)

Anthony Volodkin

On Mon, 13 Nov 2006, Anthony Volodkin wrote:

> Hi,
> Running memcached 1.2 on a set of FreeBSD 4.10, 5.4, 5.5 machines.  Using 
> Apache 2.2.3 with PHP 5.1.6 and pecl-memcache 2.1.0.
> As per the docs, a lot of my code is similar to:
> $memcache->set(md5($variable), $data, false, 7200) or error_log ("Failed to 
> set data at the server");
> While reviewing my error logs, I found tons of these errors.  Oddly, my 
> application has been working fairly well (with cache).
> I've went further and captured some memcached traffic (ngrep -s 128 "" src 
> port 11211) on one of my web servers and found no error "ERR" responses, but 
> mostly "STORED" and "NOT FOUND", which is healthy.
> How can I further troubleshoot this?  While things are generally working, 
> this really doesn't seem right.
> Thanks,
> Anthony Volodkin

More information about the memcached mailing list