无法使用apc_fetch从缓存中获取存储的变量 [英] Cannot use apc_fetch to fetch a stored variable from the cache
问题描述
环境:PHP:版本7.3操作系统:Ubuntu 18.04
Environment: PHP: version 7.3 OS: Ubuntu 18.04
后接参考文献:
我无法使用来自单独的PHP脚本"file2"的apc_fetch来访问存储的缓存.
I cannot use apc_fetch from separate PHP script "file2" to access stored cache.
从文件1触发apc_fetch时,它确实起作用.
It does work when trigger apc_fetch from file1.
文件:1_store_variable_in_memory.php
<?php
$token = "my_token_value";
apc_store('token_1', $token);
// var_dump(apc_fetch('token_1')); // Moved to file 2
文件:2_access_memory_stored_variable.php
<?php
var_dump(apc_fetch('token_1'));
文件2的结果
bool(false)
文件2的预期结果
string(14) "my_token_value"
推荐答案
进程结束后,PHP cli中的APC被清除,而且多个php cli进程之间不共享内存.因此,这可能不是您要用来解决问题的工具.
APC in PHP cli gets cleared after process is ended, moreover the memory is not shared between multiple php cli processes; because of it this is probably not the tool you want to use to solve your problem.
如果需要在进程之间保留的缓存,请尝试Redis或memcached.
Try Redis or memcached if you need a cache that is persisted between processes.
这篇关于无法使用apc_fetch从缓存中获取存储的变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!