|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #59990 getMulti can return non-unique keys
Submitted: 2011-10-04 18:40 UTC Modified: 2012-04-01 22:45 UTC
Avg. Score:4.0 ± 0.0
Reproduced:2 of 2 (100.0%)
Same Version:1 (50.0%)
Same OS:2 (100.0%)
From: nate dot whittaker at gmail dot com Assigned: andrei (profile)
Status: Closed Package: memcached (PECL)
PHP Version: Irrelevant OS: Mac OS X
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: nate dot whittaker at gmail dot com
New email:
PHP Version: OS:


 [2011-10-04 18:40 UTC] nate dot whittaker at gmail dot com
When the binary protocol is enabled and when passing the 3rd 
parameter, Memcached::GET_PRESERVE_ORDER, to getMulti(), the 
resulting array contains non-unique keys.

In other words, each key is represented twice in the result. 
One is set to null and the other is set to the value of 
whatever was stored in memcached.

getResultMessage() shows "SUCCESS".

I'm actually on php 5.3.8

Reproduce code:
$MC = new Memcached;
$MC->setOption(Memcached::OPT_BINARY_PROTOCOL, true); // Removing this causes the code to work, but at the 'expense' of reverting to the ASCII protocol
$MC->addServer('localhost', 11211);

$KeyList = Array (

$Test = Array();
foreach ($KeyList as $k) {
    $Test[$k] = 'stored value for '.$k;

// This block uses the *Multi() functions
$MC->setMulti($Test, 3600);

$null = null;
$theList = $MC->getMulti($KeyList, $null, Memcached::GET_PRESERVE_ORDER);


Expected result:
var_dump should shows:

     'key1' => 'stored value for key1'
     'key2' => 'stored value for key2'
     'key3' => 'stored value for key3'
     'key4' => 'stored value for key4'

Actual result:
var_dump shows:

     'key1' => null
     'key2' => null
     'key3' => null
     'key4' => null
     'key1' => 'stored value for key1'
     'key2' => 'stored value for key2'
     'key3' => 'stored value for key3'
     'key4' => 'stored value for key4'


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2011-10-21 21:17 UTC] nate at frickenate dot com
Confirmed. Even without the Memcached::GET_PRESERVE_ORDER option, using 
getMulti() with binary protocol enabled results in some kind of parsing problem 
that winds up making some indexes returned in the array not equal to the actual 
key requested.

I know this sounds crazy, but if I get the key "helloworld" from memcached, 
doing a var_dump() of the result shows "helloworld" index in the array - 
however, array_key_exists("helloworld", $result) fails. Somehow the index as 
seen by the eye is not the same as the actual index stored by php.

It's a little messed up - php does not allow for multiple entries of the same 
index in an array, unless memcached package somehow bypasses php's protections. 
I would guess that there is a NULL (byte 0) character in the string somewhere, 
but this is not the case. If I dump the serialize() or json_encode() of the 
array, a NULL character is nowhere to be seen.

Thanks to the other Nate (strange coincidence) for bringing the binary protocol 
to light. I couldn't track down the cause of this behaviour myself, however 
disabling binary protocol in the client does indeed solve the problem.
 [2012-02-19 07:25 UTC] iamcraigcampbell at gmail dot com
I just experienced this exact bug and thought I was going crazy.  Didn't think it 
was possible for an array to have multiple entries with the same index.  Glad to 
see I'm not the only one.
 [2012-04-01 22:44 UTC]
-Summary: getMulti can return non-unique keys +Summary: Add binary session support -PHP Version: 5.3.6 +PHP Version: Irrelevant
 [2012-04-01 22:45 UTC]
-Summary: Add binary session support +Summary: getMulti can return non-unique keys -Status: Open +Status: Closed -Assigned To: +Assigned To: andrei
 [2012-04-01 22:45 UTC]
Opened on Github as an issue, closing this here.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Jul 24 21:01:28 2024 UTC