PHP Memcached 错误

4

每次我尝试使用memcached的add()函数时,都会出现以下错误:

A PHP Error was encountered

Severity: Warning

Message: MemcachePool::add(): The lowest two bytes of the flags array is reserved for pecl/memcache internal use

Filename: libraries/memcached_library.php

Line Number: 92

可能出了什么问题?我正在使用这个库来支持codeigniter:http://github.com/trs21219/memcached-library

4个回答

14

你是否在64位系统上?看起来这是一个最近发现的pecl/memcache bug:http://pecl.php.net/bugs/bug.php?id=18567

这个问题似乎与压缩标志有关。根据这个源代码,它不能再是布尔值,而必须是整数。

/**
 * The compressed argument on Memcache::add, Memcache::set and Memcache::replace takes
 * an integer not a boolean. Since pecl/memcache 3.0.3 booleans now leads to warnings like
 * The lowest two bytes of the flags array is reserved for pecl/memcache internal use
 */

2
太好了,谢谢。我把压缩从TRUE改成了0,现在一切都正常了。 - Matthew
我在Windows上使用Memcache时遇到了同样的问题。只需重申,如果传递,则“Compression”将是第三个参数,需要为0才能解决它。参考:http://php.net/manual/en/memcache.set.php - kta

7
也许这是你的情况:一些关于使用memcache的手册,例如http://www.codeforest.net/how-to-install-memcached-on-windows-machine,存在一个错误
$memcache->add("key", $tmp, 30);

但是正确使用过期秒数参数(这里是30秒)的方法是:

$memcache->add("key", $tmp, MEMCACHE_COMPRESSED, 30);

或者像这样。
$memcache->add("key", $tmp, false, 30);

正确示例的手动样本:http://zurmo.org/wiki/installing-memcache-on-windows
另请参阅文档http://php.net/manual/ru/memcache.add.php

对我来说,这是关键。


5
您可以将“false”作为第三个参数添加,这对我有用。
Warning (2): MemcachePool::add() [memcachepool.add]: The lowest two bytes of the flags array is reserved for pecl/memcache internal use

From:
return $this->memcache->add($name, $value, $expiry);

To:
return $this->memcache->add($name, $value, false, $expiry);

是的,在PHP中,Memcache和Memcached方法是不同的。 - Victor Perov

1
这可能对一些人有所帮助,我下载了一个用于CodeIgniter的库,该库使用的是memcache而不是memcached用于会话。它可以在此处找到:https://github.com/pierskarsenbarg/codeigniter-session-memcached
对我来说问题是当库使用

memcache->set()

and/or
memcache->replace()

第三个参数是过期时间而不是有效的标志类型。
即MEMCACHE_COMPRESSED。
示例:
原始代码:
$this->memcache->set('user_session_data' . $this->userdata['session_id'], $this->userdata, $this->sess_expiration); 

改变的代码:
$this->memcache->set('user_session_data' . $this->userdata['session_id'], $this->userdata, MEMCACHE_COMPRESSED, $this->sess_expiration);

在将第三个参数更改为正确的标志类型后,错误消失了。

1
你的回答实际上和我一样,但是关于CodeIgniter Memcached功能的错误问题。我认为这也很有用 - 点赞。 - FlameStorm

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接