APCu is a shared memory key-value store for PHP. The memory is shared between PHP-FPM processes of the same pool. Stored data persists between requests.

Simple storage and retrieval

apcu_store can be used to store, apcu_fetch to retrieve values:

$key = 'Hello';
$value = 'World';
apcu_store($key, $value);
print(apcu_fetch('Hello')); // 'World'

Store information

apcu_cache_info provides information about the store and its entries:


Note that invoking apcu_cache_info() without limit will return the complete data currently stored.
To only get the meta data, use apcu_cache_info(true).
To get information about certain cache entries better use APCUIterator.

Iterating over Entries

The APCUIterator allows to iterate over entries in the cache:

foreach (new APCUIterator() as $entry) {

The iterator can be initialized with an optional regular expression to select only entries with matching keys:

foreach (new APCUIterator($regex) as $entry) {

Information about a single cache entry can be obtained via:

$key = '…';
$regex = '(^' . preg_quote($key) . '$)';
print_r((new APCUIterator($regex))->current());