**更新06/23 **
在这一点上,我能够将问题隔离为一个简单的例子。首先,我存储了一些示例项目:
apc_add('MY_APC_TESTA_1','1');
apc_add('MY_APC_TESTA_2','2');
apc_add('MY_APC_TESTA_3','3');
apc_add('MY_APC_TESTB_4','4');
apc_add('MY_APC_TESTB_5','5');
apc_add('MY_APC_TESTB_6','6');然后,我使用APCIterator检索这些项,使用foreach循环对它们进行计数,并使用apciterator类的getTotalCounts方法进行双重检查。
$iterator = new APCIterator('user', '/^MY_APC/', APC_ITER_VALUE);
function showCache() {
echo "keys in cache<br>-------------<br>";
foreach ($items AS $key => $value) {
echo $key . "<br>";
}
}
$i = 0;
foreach ($iterator as $current_item) {
$i++;
}
echo 'getTotalCount: '.$iterator->getTotalCount().'<br>'; // output: 6
echo 'foreach count: '.$i.'<br>'; // output: 6
showCache();在存储了要获得此输出的项后立即调用此脚本:
getTotalCount: 6
foreach count: 6
keys in cache
-------------
MY_APC_TESTA_1
MY_APC_TESTA_2
...几小时或一天后调用此脚本,我将收到以下输出:
getTotalCount: 6
foreach count: 0
keys in cache
-------------因此,正如您可以看到的那样,迭代器类仍然可以使用其方法getTotalCount检索总数,但是尽管它在几个小时前已经工作,但是foreach循环会带来空的结果。这就是为什么我的缓存处理程序不能工作的原因,因为它们使用apciterator和apc_delete($iterator)来获取相应的项,并在修改之后清除它们。因为foreach/数组是空的,所以没有什么要删除的。这是个大问题。我不认为这是预期的行为。有什么办法吗?
在我的VPS上有以下设置:
APC设置:
apc.cache_by_default 1
apc.canonicalize 1
apc.coredump_unmap 0
apc.enable_cli 0
apc.enabled 1
apc.file_md5 0
apc.file_update_protection 2
apc.filters
apc.gc_ttl 3600
apc.include_once_override 0
apc.lazy_classes 0
apc.lazy_functions 0
apc.max_file_size 1M
apc.mmap_file_mask /tmp/apc.Z1n8dS
apc.num_files_hint 512
apc.preload_path
apc.report_autofilter 0
apc.rfc1867 0
apc.rfc1867_freq 0
apc.rfc1867_name APC_UPLOAD_PROGRESS
apc.rfc1867_prefix upload_
apc.rfc1867_ttl 3600
apc.serializer default
apc.shm_segments 1
apc.shm_size 256M
apc.shm_strings_buffer 4M
apc.slam_defense 1
apc.stat 1
apc.stat_ctime 0
apc.ttl 7200
apc.use_request_time 1
apc.user_entries_hint 4096
apc.user_ttl 7200
apc.write_lock 1发布于 2017-08-02 00:39:09
APCIterator错误地只返回比apc.ttl年轻的缓存条目,但是它在getTotalCount()返回的数字中包含了这些条目。
我在这里为这个bug提交了一个拉请求:https://github.com/krakjoe/apcu/pull/253
https://stackoverflow.com/questions/37969063
复制相似问题