memcache PECL bug fix

使用 memcache 的过程中,遇到一个奇怪的问题,在 CentOS 环境下,PHP 的 memcache 扩展创建的客户端对象,在 delete 一个 key 的时候报错:

[25-Nov-2009 13:57:04] PHP Notice:  Memcache::delete(): Server 192.168.10.131 (tcp 11211) failed with: CLIENT_ERROR bad command line format.  Usage: delete <key> [noreply]

可是在 Windows 环境下,用的人家编译好的 php_memcache-cvs-20090703-5.3-VC6-x86.dll (20KB) 却没问题!

在 Google 上找了半天,终于在 PHP 官方手册的评论中发现了线索:

http://php.net/manual/en/function.memcache-delete.php

请看 10-Nov-2009 11:17 这条,简短翻译一下:

memcache 这个 PECL 扩展的 2.2.5 稳定版本有一个错误,导致在向 memcached 1.4.3 调用 delete 方法时返回 false。

用 -vvv 模式运行 memcached 将显示出为什么 delete 调用失败:

CLIENT_ERROR bad command line format.  Usage: delete <key> [noreply]

简单修改一下,在这个 PECL 扩展的 memcache.c 这个文件的 1494 行的 mmc_delete() 函数中。把 command_len 修改为下面这样:

command_len = spprintf(&command, 0, “delete %s”, key);

去掉了弃用的第 3 个参数,然后 delete 就可以工作了。希望这个可以帮到你!

再提示一下改动前的代码:

//  command_len = spprintf(&command, 0, “delete %s %d”, key, time);

修改完成后,重新编译出 memcache.so 即可。

Tags: ,

Leave a Reply

Your email address will not be published.

*