php memcached error
Solution 1
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
*/
Solution 2
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.
Solution 3
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);
Solution 4
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.
Matthew
Updated on June 04, 2022Comments
-
Matthew almost 2 years
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
-
Matthew over 13 yearsPerfect. Thanks. I changed compression from TRUE to 0 and everything works fine now.
-
Victor Perov over 9 yearsYes, Memcache and Memcached methods in the PHP are differs
-
FlameStorm about 8 yearsYou answered in fact just the same I do upper, but about codeigniter memcached feature bug. I think it's useful too - upvote.
-
kta over 7 yearsI was using Memcache on windows and facing the same issue. Just to repeat, 'Compression' will be the third argument if passes which need to be 0 to resolve it. Ref:php.net/manual/en/memcache.set.php