Search code examples
phpcachingiteratorapc

apciterator can't retrieve items after certain amount of time


**Update 06/23 **

At this point I was able to isolate the issue to a simple example. Firstly I store some example items:

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');

Then I use APCIterator for retrieving the items, counting them with a foreach loop and additionally using getTotalCounts method of apciterator class for double checking.

$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();

Calling this script right after storing the items I am getting this output:

getTotalCount: 6
foreach count: 6
keys in cache
-------------
MY_APC_TESTA_1
MY_APC_TESTA_2
...

Calling this script couple of hours or a day later I receive this output:

getTotalCount: 6
foreach count: 0
keys in cache
-------------

So as you can see the iterator class can still retrieve the total count using its method getTotalCount but a foreach loop brings empty results although it was working a couple of hours earlier. That's the reason why my cache handlers are not working because they are using apciterator in conjunction with apc_delete($iterator) to get corresponding items and clear them once a modification was made. Since the foreach/array is empty there is nothing to delete. This is a huge problem. I don't assume that this is expected behavior. Any ideas how is this possible?

I am having the following setup on my VPS:

  • CentOS 7
  • Nginx with PHP-FPM
  • PHP 5.4.16
  • APC 3.1.13

APC Settings:

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

Solution

  • APCIterator erroneously only returns cache entries that are younger than apc.ttl, but it includes these in the number returned by getTotalCount().

    I've submitted a pull request for this bug here: https://github.com/krakjoe/apcu/pull/253