zendframework / zf1

This project reached its end-of-life on 2016-09-28. Contains conversion of ZF1 subversion repo to git, from version 15234 forward, and only containing master and release-1.12 branches and 1.12 tags.
https://framework.zend.com/blog/2016-06-28-zf1-eol.html
BSD 3-Clause "New" or "Revised" License
358 stars 795 forks source link

Bug in Zend_Cache_Backend_Apc::getIds() #249

Closed jianzhong closed 10 years ago

jianzhong commented 10 years ago

The getIds() method is looking for an array item indexed with 'info' in the array returned by calling apc_cache_info(), but the key doesn't exist. The key name has changed to 'key', instead of 'info'. See the apc_cache_info() return value below.

array(14) {
  ["nslots"] => int(4099)
  ["ttl"] => int(0)
  ["nhits"] => float(1)
  ["nmisses"] => float(0)
  ["ninserts"] => float(1)
  ["nentries"] => int(1)
  ["nexpunges"] => float(0)
  ["stime"] => int(1386244867)
  ["mem_size"] => float(656)
  ["file_upload_progress"] => int(1)
  ["memory_type"] => string(4) "mmap"
  ["cache_list"] => array(1) {
    [0] => array(9) {
      ["key"] => string(5) "test1"
      ["ttl"] => int(3600)
      ["nhits"] => float(1)
      ["mtime"] => int(1386244910)
      ["ctime"] => int(1386244910)
      ["dtime"] => int(0)
      ["atime"] => int(1386244910)
      ["ref_count"] => int(0)
      ["mem_size"] => int(656)
    }
  }
  ["deleted_list"] => array(0) {
  }
  ["slot_distribution"] => array(1) {
    [1140] => int(1)
  }
}

My php version is 5.5.3, and has APCu module enabled.

fonzai commented 10 years ago

In Apc.conf:

public function getIds()
{
    $res = array();
    $array = apc_cache_info('user', false);
    var_dump($array['cache_list']);
    $records = $array['cache_list'];
    foreach ($records as $record) {
            $res[] = $record['info'];
    }
    return $res;
}

I fixed it temporarily like this:

public function getIds()
{
    $res = array();
    $array = apc_cache_info('user', false);
    var_dump($array['cache_list']);
    $records = $array['cache_list'];
    foreach ($records as $record) {
        if (isset($record['info'])) {
            $res[] = $record['info'];
        } else {
            $res[] = $record['key'];
        }
    }
    return $res;
}

But cleaner solution would probably be to use APCIterator instead of relying on the apc_cache_info structure which can change.