php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #58639 php index key problem on multi get
Submitted: 2009-04-21 10:38 UTC Modified: 2011-03-10 21:58 UTC
From: black at scene-si dot org Assigned:
Status: No Feedback Package: memcache (PECL)
PHP Version: 5.2.6 OS: Linux Debian Lenny
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: black at scene-si dot org
New email:
PHP Version: OS:

 

 [2009-04-21 10:38 UTC] black at scene-si dot org
Description:
------------
Fetching multiple keys from array works as expected in var_dump, but isset() returns false on existing key. Foreach over the results and overwriting key/value pairs, creates duplicate keys inside the array itself.

I can reproduce the test with a clean memcache instance.

Memcache Extension version: 3.0.1
memcached 1.2.2

PHP 5.2.6-1+lenny2 with Suhosin-Patch 0.9.6.2 (cli) (built: Jan 26 2009 22:41:04)

Linux rtvdevnews 2.6.26-1-686 #1 SMP Sat Jan 10 18:29:31 UTC 2009 i686 GNU/Linux


Reproduce code:
---------------
<?php

$keys['forum'] = "_sql_forum_last_forum_topics";
$keys['photos'] = "_sql_photos_last";
$keys['videos'] = "_sql_videos_last";
$keys['audios'] = "_sql_audios_last";
$keys['blog'] = "_sql_blog_last";
$keys['popotnik'] = "_sql_popotnik_last";
$keys['mojsvet'] = "_sql_mojsvet_last";
$keys['klepetalnica'] = "_sql_klepetalnica_last";

$cache = array();

$key = "photos";

$mc = new Memcache;
$mc->addServer("localhost", 11211);


$mc->set("_sql_forum_last_forum_topics", array (
  0 =>
  array (
    'topic_id' => '25255',
    'forum_id' => '7',
    'topic_title' => 'S-t-a-v-e',
    'topic_time' => '1240323473',
    'topic_last_post_id' => '1590262',
    'forum_name' => 'Razno',
  ),
));

$mc->set("_sql_photos_last", array (
  0 =>
  array (
    'id' => '87097',
    'album_id' => '13310',
    'file_id' => '89021',
    'score' => '0',
    'cover' => NULL,
    'title' => 'Slika uporabnika veseljakinja',
    'caption' => NULL,
    'stamp' => '2009-04-21 16:06:16',
    'vote_count' => '0',
    'vote_sum' => '0',
    'voting_show' => '1',
    'tags' => '',
    'seen' => '',
    'visible' => '1',
    'listed' => '1',
    'category' => '0',
    'user_id' => '65748',
    'date' => '<a href="/slike/koledar/2009/04/21/">21.04.2009</a> || 16:06:16',
    'date_diff' => 'pred 8 minutami',
    'rating' => '0.0',
    'rating_count' => '0',
    'link' => '/slike/photo/87097',
    'show' => '/_up/photos/2009/04/21/u65748-87145_8396209_show.jpg',
    'thumb' => '/_up/photos/2009/04/21/u65748-87145_8396209_thumb.jpg',
    'small' => '/_up/photos/2009/04/21/u65748-87145_8396209_small.jpg',
    'author' => 'veseljakinja',
    'author_link' => '/profil/veseljakinja',
  ),
));

$cache = $mc->get(array_values($keys));

echo "array_keys ";
debug_zval_dump(array_keys($cache));
echo "isset ";
debug_zval_dump(isset($cache[$keys[$key]]));
echo "in_array/array_keys ";
debug_zval_dump(in_array($keys[$key],array_keys($cache)));

foreach ($cache as $k=>$v) {
        $cache[$k] = $v;
}

echo "array_keys ";
debug_zval_dump(array_keys($cache));
echo "isset ";
debug_zval_dump(isset($cache[$keys[$key]]));
echo "in_array/array_keys ";
debug_zval_dump(in_array($keys[$key],array_keys($cache)));


Expected result:
----------------
array_keys array(2) refcount(1){
  [0]=>
  string(28) "_sql_forum_last_forum_topics" refcount(1)
  [1]=>
  string(16) "_sql_photos_last" refcount(1)
}
isset bool(true) refcount(1)
in_array/array_keys bool(true) refcount(1)
array_keys array(3) refcount(1){
  [0]=>
  string(28) "_sql_forum_last_forum_topics" refcount(1)
  [1]=>
  string(16) "_sql_photos_last" refcount(1)
}
isset bool(true) refcount(1)
in_array/array_keys bool(true) refcount(1)


Actual result:
--------------
array_keys array(2) refcount(1){
  [0]=>
  string(28) "_sql_forum_last_forum_topics" refcount(1)
  [1]=>
  string(16) "_sql_photos_last" refcount(1)
}
isset bool(false) refcount(1)
in_array/array_keys bool(true) refcount(1)
array_keys array(3) refcount(1){
  [0]=>
  string(28) "_sql_forum_last_forum_topics" refcount(1)
  [1]=>
  string(16) "_sql_photos_last" refcount(1)
  [2]=>
  string(16) "_sql_photos_last" refcount(1)
}
isset bool(true) refcount(1)
in_array/array_keys bool(true) refcount(1)


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-04-21 10:49 UTC] black at scene-si dot org
I tried it on another machine, with PHP 5.2.0-8+etch13 (cli) (built: Oct  2 2008 08:26:18)

- Cannot reproduce, with the same instance of memcached over network, unknown memcache extension (so it's either memcached extension or PHP/suhoshin problem).
 [2010-01-29 12:36 UTC] jozsef dot rnagy at site dot hu
Managed to run into the same problem, was debugging for hours, no idea what's causing it.
also on Debian
 [2010-07-15 05:33 UTC] black at scene-si dot org
I managed to reproduce the error today on debian lenny, php 5.2.6-lenny6/8 patchset, and the bundled php5-memcached 3.0.1 extension. Sadly, it was in production.

A simple foreach like this is a temporary workaround:

$multiget_copy = array();
foreach ($multiget_data as $k=>$v) {
   $multiget_copy[$k] = $v;
}
$multiget_data = $multiget_copy;

Best regards,
Tit
 [2010-10-05 14:23 UTC] hradtke@php.net
I just went and tested this.  I cannot recreate the problem anymore.  Is this still happening for you?
 [2011-03-10 21:58 UTC] hradtke@php.net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Open". Thank you.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Dec 09 02:01:27 2024 UTC