phpcachingpeclapcu

APCu doesn't store in PHP 7


APCu will only fetch values that were stored in the current page load.

Refreshing this twice:

<?php 
var_dump(apcu_fetch("test"));

apcu_store("test", "works", 3600);
var_dump(apcu_fetch("test"));
?>

outputs the following:

bool(false) string(5) "works"

So it stores the data while the current page is loading. After that it doesn't exist anymore...

I'm using the latest stable version (5.1.2) with the default configuration on PHP 7.0.0.

I've tried different versions of APCu and PHP 7. Also can't find anything similar on Google...

This is my PHP apcu configuration: Broken APCu configuration


Solution

  • APC(u) is intended to function in a prefork multiprocess, or multithreaded SAPI.

    FastCGI (without FPM) and CGI are not prefork models, they spawn distinct processes, as such APC(u) will not work correctly in those environments.

    Nor will anything that uses shared mapped memory, like Opcache: They can cache for the current process, but share they cannot.