krakjoe / apcu

APCu - APC User Cache
Other
964 stars 196 forks source link

Stored data doesn't persist between multiple instances of PHP #427

Closed erfanmola closed 2 years ago

erfanmola commented 2 years ago

Hi, I'm using APCu with lsphp8, and here is my php.ini :

apc.enabled=1
apc.shm_size=512M
apc.ttl=3600
apc.user_ttl=7200
apc.gc_ttl=3600
apc.enable_cli=1
apc.serializer=igbinary

and here is my code :

$array = (array_fill(0, 10240, "ABC"));
$result = apcu_store((string)$key, $array);
$result = apcu_fetch((string)$key);

I am running my php Script via cli, It is able to store/fetch in a single process, but when I comment the 2nd line and try to fetch from previously stored data, It returns false

Previously I was able to open a persistent MemoryBlock using shmop, but the problem is shmop is super super super slow in working with Memory or at least opening a large block size, while apcu is fast (not the speed I expected, but super faster than shmop)

nikic commented 2 years ago

apcu only support sharing data across forked process or threads, i.e. a typical non-Windows web server setup. If you want to cache data in a process-independent way, you should use an external in-memory data store, like memcached or redis.