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

杀马特。学长 韩版系。学妹 提交于 2019-12-08 02:55:51

问题


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

With APC

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

With APCu

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 $ret to be empty.

While, with shmop:

$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 $ret: "bar".

Shouldn't the APC/APCu cache the intermediate result locally just as the shmop?


回答1:


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.



来源:https://stackoverflow.com/questions/37770197/php-apc-apcu-cache-do-not-keep-intermediate-result-while-shmop-do-why

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!