lulyon lulyon - 3 years ago 153
PHP Question

PHP apc/apcu cache do not keep intermediate result while shmop do, why?

I've encounter a problem with PHP to store intermediate result locally.



apc_store("foo", "bar");
$ret = apc_fetch("foo");


apcu_store("foo", "bar", 0);
$ret = apcu_fetch("foo");

I store with apc_store/apcu_store under php_cli on a php script, and fetch with apc_fetch/apcu_fetch on another php script, and find the
to be empty.

While, with

$shmKey = ftok(__FILE__, 't');
$shmId = shmop_open($shmKey, "c", 0644, 1024);
$dataArray = array("foo" => "bar");
shmop_write($shmId, serialize($dataArray), 0);

$retArray = unserialize(shmop_read($shmId, 0, shmop_size($shmId)));
$ret = $retArray['foo'];

Here I get the

Shouldn't the
cache the intermediate result locally just as the

Answer Source

Both APC and APCu share the memory across the same process they run in however you cannot use that with different processes. They intended to work on a prefork multiprocess or multithreaded applications (apache/php-fpm/etc).

The CLI version of APCu is there mostly to help with testing, but if you run a code using the CLI and then run another instance of the CLI - you will not have the data from your first run (the same will happen if you will restart your web server).

It's unfortunate that this information is not clear in the documentation.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download