Memcached bug in PHP - binary protocol -
i came across bug using memcached in php. here's piece of code:
<?php $mc = new \memcached(); $mc->setoption(\memcached::opt_binary_protocol, true); $mc->addserver("127.0.0.1", 11211); $mc->touch("key", time() + 600); $touchresult = $mc->getresultcode(); $mc->set("key", 1, time() + 600); $setresult = $mc->getresultcode(); echo "<pre>"; echo "touch result: $touchresult\n"; echo "set result: $setresult\n"; echo "</pre>";
when run first time, output:
touch result: 16 set result: 0
and second time forth:
touch result: 0 set result: 5
correct me if i'm wrong bug right? know workaround this?
here versions use:
- ubuntu 12.04 64bit
- php 5.3.14
- memcached 2.1.0 (pecl module)
- libmemcached 1.0.8
- memcached sever 1.4.13
ps. if wonder result codes mean, here are:
0 res_success 5 res_write_failure 16 res_notfound
[update]
i played little more code , found more interesting. bug happens regardless of key
touch
, set
working on. long touch
operation returns 0
(which means successful) set
operation fail.
[update]
i managed produce other errors well. e.g. acquiring key
server , add
ing other lead nasty problems (res_end
code). believe these problems somehow related binary protocol. seems me if binary protocol's implementation hardly near stable. operations can work without binary protocol fine once protocol set binary, result in blocking problems.
all right.
in first time, touch not existed key - result res_notfound. when set - write value success - res_success.
in next time touch existed key (you set in first linch) , result of operation res_success, next try set value existed key - result false. right.
if want change existing value must use memcached::replace() method instead of "set"
Comments
Post a Comment