Search code examples
phpphp-5.6opcache

very large 2.5mb php file will opcache cache it?


I have a project in which I have a large array with locations having certain timezones.

I do not wish to use a database because that would mean too many database hits and writing Yet Another Caching Mechanism to prevent database hits.

So I made it into a php file with arrays. Currently it's 2.5mb on disc.
I could trim down the arrays to save on some info I don't need at this point in time but might in the future(geographic location, city names, altitude etc..)

Since I have opcache enabled, I am hoping that opcache will cache this very large file, saving the disc hits, keeping the data readily available.

can someone confirm opcache will also cache this large 2.5mb file? or give me a method to test/verify this file is cached?


Solution

  • Yes, opcache will cache it.

    By looking at the code from the tool commented by MarkBaker I was able to get this simple verify script out to see if the file is cached or not.

    Al you need is the absolute path to the file, and then you can easily check if it's cached or not.

    <pre><?php 
    $status = opcache_get_status();
    $scripts = $status['scripts'];
    $file = 'F:\cmslib-dev\include\lib\locations\Locations.php';
    
    if(array_key_exists($file, $scripts)) {
        var_dump($scripts[$file]);
    }
    else {
        echo "$file is not cached";
    }
    ?>
    </pre>