Search code examples
apcphp

Apc user cache and php-fpm


I have a pretty basic doubt on dirty read/writes to a value stored in apc when php-fpm is used to manage process. i am looking at storing a counter in apc which i want to be shared across all the PHP fpm processes. The counter is used for the lo part of the hilo algorithm. Since apc user cache is shared across all the fpm child processes, i can basically increment this counter without having to worry about multiple processes having their own copy of the counter. But if the cache is shared, wouldn't you have to worry about thread safety? If yes, how do you go about doing that and if no, why not? Thanks!


Solution

  • Didn't figure out how to do it with apc but have decided to use shared memory with semaphores to store the counter: https://www.php.net/sem.