3

Among the data points returned by opcache_get_status() is:

'opcache_statistics' => [
    'num_cached_scripts' => 90,
    'num_cached_keys' => 96,
    'max_cached_keys' => 3907,
    ...
]

The number of cached scripts is correct and understandable (and can be confirmed by counting the 'scripts' part of the return value). But what exactly does "keys" refer to? I assume the Zend OPcache could be organized as a key/value store. In that case, there should be a one-to-one relationship between scripts and keys, unless...

  • the OPcache also stores something other than scripts, or
  • some of the scripts are stored using 2 or more keys

I didn't see an API for listing the keys used by the OPcache.

Zilk
  • 8,917
  • 7
  • 36
  • 44
  • 1
    The point of these is that the table sizes are set at startup and once full OPcache can't cache any more scripts. These just allow sysadmins to monitor these fixed limits so that they know when to up them for the next restart. – TerryE May 07 '14 at 18:31

1 Answers1

5

OPcache keeps separate num_entries and num_direct_entries statistics for each of its hash tables; these values directly correspond to num_cached_keys and num_cached_scripts in the result of opcache_get_status.

There's comments in the code that directly supports your second assumption: some stuff is cached under more than one key.

Jon
  • 428,835
  • 81
  • 738
  • 806
  • 1
    There's no better explanation than the source, thank you. For posterity, the linked comment reads: _Few keys may be resolved to the same data using 'indirect' entries, that point to other entries […]_ – Zilk May 07 '14 at 12:33