PHP apc/apcu缓存不保持中间结果,而shmop保持中间结果,为什么? [英] PHP apc/apcu cache do not keep intermediate result while shmop do, why?
问题描述
我在使用PHP时遇到问题,无法在本地存储中间结果.
I've encounter a problem with PHP to store intermediate result locally.
使用APC
:
apc_store("foo", "bar");
$ret = apc_fetch("foo");
使用APCu
:
apcu_store("foo", "bar", 0);
$ret = apcu_fetch("foo");
我将apc_store/apcu_store与apc_store/apcu_store存储在一个php脚本的php_cli下,并与apc_fetch/apcu_fetch一起存储在另一个php脚本中,并且发现$ret
为空.
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.
同时使用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'];
在这里我得到$ret
:"bar"
.
APC/APCu
是否应该像shmop
一样在本地缓存中间结果?
Shouldn't the APC/APCu
cache the intermediate result locally just as the shmop
?
推荐答案
两者 APC 和 APCu 在它们运行的同一过程中共享内存,但是您不能将其用于不同的流程.他们打算在prefork多进程或多线程应用程序(apache/php-fpm/etc)上工作.
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).
APCu的CLI版本主要用于帮助测试,但是如果您使用CLI运行代码,然后运行CLI的另一个实例-您将没有第一次运行的数据(如果您将重新启动Web服务器.)
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.
这篇关于PHP apc/apcu缓存不保持中间结果,而shmop保持中间结果,为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!