php memcached error
Every time I try to use the add() function for memcached, I get the following error:
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
What could be wrong? I'm using this library for codeigniter: http://github.com/trs21219/memcached-library
Are you on 64 bits? It looks like it's a recently found bug with pecl/memcache: http://pecl.php.net/bugs/bug.php?id=18567
It seems like it has to do with the compression flag. It can't be a boolean anymore, it needs to be an integer according to this source code
/**
* 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
*/
May be it's your case: some manuals for memcache using, like http://www.codeforest.net/how-to-install-memcached-on-windows-machine, have a mistake:
$memcache->add("key", $tmp, 30);
but correct use of expiration seconds parameter (30 sec here) is:
$memcache->add("key", $tmp, MEMCACHE_COMPRESSED, 30);
or like
$memcache->add("key", $tmp, false, 30);
Sample of manual with correct example: http://zurmo.org/wiki/installing-memcache-on-windows
See also documentation http://php.net/manual/ru/memcache.add.php
For me it was the key.
You can add 'false' as the third parameter, it worked for me.
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);
This might be helpful for some, I had downloaded a library for codeigniter that made use of memcache not memcached for sessions. It can be found here: https://github.com/pierskarsenbarg/codeigniter-session-memcached
The problem for me was that when the lib was using
memcache->set()
and/or
memcache->replace()
the third parameter was the expire time and not a valid flag type.
i.e. MEMCACHE_COMPRESSED
Example
Original Code:
$this->memcache->set('user_session_data' . $this->userdata['session_id'], $this->userdata, $this->sess_expiration);
Changed Code:
$this->memcache->set('user_session_data' . $this->userdata['session_id'], $this->userdata, MEMCACHE_COMPRESSED, $this->sess_expiration);
After changing the third parameter to a correct flag type the error went away.
精彩评论