Cannot use apc_fetch to fetch a stored variable from the cache

我的梦境 提交于 2020-02-05 02:46:07

问题


Environment: PHP: version 7.3 OS: Ubuntu 18.04

References followed:

PHP - apc_store

PHP - apc_fetch


I cannot use apc_fetch from separate PHP script "file2" to access stored cache.

It does work when trigger apc_fetch from file1.


File: 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

File: 2_access_memory_stored_variable.php

<?php

var_dump(apc_fetch('token_1'));

Result from file 2:

bool(false)

Expected result from file 2:

string(14) "my_token_value"

回答1:


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.

Try Redis or memcached if you need a cache that is persisted between processes.



来源:https://stackoverflow.com/questions/60054235/cannot-use-apc-fetch-to-fetch-a-stored-variable-from-the-cache

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