5

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

Andrea
  • 19,134
  • 4
  • 43
  • 65

1 Answers1

10

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.

Joe Watkins
  • 17,032
  • 5
  • 41
  • 62
  • Is there a warning on the site about this? Maybe APCu should refuse to load in those SAPIs, like pthreads does. – Andrea Dec 17 '15 at 15:16
  • 1
    I'll discuss it with other maintainers ... or anyone who wants to say anything ... https://github.com/krakjoe/apcu/issues/161 – Joe Watkins Dec 17 '15 at 15:28