问题
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