Cache Hits

Verifying Cache Hits and Wasted Memory

opcache_get_status(false) returns the counters without the per-script list. Serve a page like this from the pool you are tuning, behind Require local or a login:

opstatus.php: the OPcache counters that matterPHP
<?php
$s = opcache_get_status(false);
$m = $s['memory_usage'];
$st = $s['opcache_statistics'];
printf("scripts %d  hits %d  misses %d  hit rate %.2f%%\n", $st['num_cached_scripts'],
    $st['hits'], $st['misses'], $st['opcache_hit_rate']);
printf("used %.1f MB  free %.1f MB  wasted %.1f MB (%.2f%%)\n", $m['used_memory'] / 2**20,
    $m['free_memory'] / 2**20, $m['wasted_memory'] / 2**20, $m['current_wasted_percentage']);
printf("interned strings %.1f of %.1f MB  restarts oom=%d hash=%d manual=%d\n",
    $s['interned_strings_usage']['used_memory'] / 2**20,
    $s['interned_strings_usage']['buffer_size'] / 2**20,
    $st['oom_restarts'], $st['hash_restarts'], $st['manual_restarts']);

After a 10-second load test on the Laravel 2,157 page:

Output of 239
scripts 496  hits 8737559  misses 496  hit rate 99.99%
used 22.3 MB  free 105.7 MB  wasted 0.0 MB (0.00%)
interned strings 5.1 of 8.0 MB  restarts oom=0 hash=0 manual=0

A hit is one file served from cache, so one page view scores hundreds. Touching the framework's files and requesting the page again turned 5.2 MB (4.04%) into wasted memory. On a warm server, expect a hit rate near 100%, free memory, room in the interned-strings buffer, and zero restarts. Wasted memory is held by outdated copies of changed files; past max_wasted_percentage (5%) OPcache restarts and recompiles everything. Rising oom_restarts means memory_consumption is too small, and rising hash_restarts means max_accelerated_files is.