APC values randomly disappear

Posted by Michael on Stack Overflow See other posts from Stack Overflow or by Michael
Published on 2010-12-17T08:32:41Z Indexed on 2010/12/21 5:54 UTC
Read the original article Hit count: 328

Filed under:
|

I'm using APC for storing a map of class names to class file paths. I build the map like this in my autoload function:

$class_paths = apc_fetch('class_paths');

// If the class path is stored in application cache - search finished.

if (isset($class_paths[$class])) {
    return require_once $class_paths[$class];

// Otherwise search in known places

} else {

    // List of places to look for class

    $paths = array(
        '/src/',
        '/modules/',
        '/libs/',
    );

    // Search directories and store path in cache if found.

    foreach ($paths as $path) {
        $file = DOC_ROOT . $path . $class . '.php';
        if (file_exists($file)) {
            echo 'File was found in => ' . $file . '<br />';

            $class_paths[$class] = $file;
            apc_store('class_paths', $class_paths);
            return require_once $file;
        }
    }   
}

I can see as more and more classes are loaded, they are added to the map, but at some point the apc_fetch returns NULL in the middle of a page request, instead of returning the map.

Getting => class_paths
Array
(
    [MCS\CMS\Helper\LayoutHelper] => /Users/mbl/Documents/Projects/mcs_ibob/core/trunk/src/MCS/CMS/Helper/LayoutHelper.php
    [MCS\CMS\Model\Spot] => /Users/mbl/Documents/Projects/mcs_ibob/core/trunk/src/MCS/CMS/Model/Spot.php
)
Getting => class_paths
{null}

Many times the cached value will also be gone between page requests.

What could be the reason for this?

I'm using APC as an extension (PECL) running PHP 5.3.

© Stack Overflow or respective owner

Related posts about php

Related posts about apc