I have a PHP 7.4 set of scripts running with APCu extension, which is used by the code as a general object store for all users who visit the single hosted website. Due to my own lack of understanding, I later found out that the APCu cache is established per PHP process. So what I am seeing is that in some cases user 'a' is getting a different cached value than user 'b' (presumably since PHP-FPM has forked a new process for user 'b').
But it's still not clear to me exactly how to set up php-fpm so that all incoming requests will be inside of child processes that are derived from the same parent process.
APCu guru krakjoe said this back in 2015 (my emphasis in bold):
Just to answer the original question ... as @fruitl00p said, you can
configure your way out of the problem of not being able to share if
you are using fpm.
There is a difference between using fpm and using fcgi, I should
probably put in a PR to phptherightway to clear it up.
The rule is that only child processes can access what their parent
created; In FCGI spawned processes are not necessarily a child of
their parent, they may not be actual forks. If your process manager
works like conventional FCGI/CGI then you will not be able to share,
if it works like FPM, and initializes PHP in a parent and forks child
interpreters then you will have no problem.
Further research led me to php-fpm www.conf file and the settings for:
pm = dynamic
pm.max_children = 50
So - is it as simple as changing this to:
pm = static
pm.max_children = 50
i.e. is this the way to force php-fpm to make sure all child processes point back to a single parent? Thus, assuring that there is only one global APCu cache in play? I realize that I need to do math to figure out the correct pm.max_children value.
Please note: I can't switch to memcached at this point, since I am relying on a regex iteration over the APCu keys via an APCUIterator object. I may get there eventually, but as of now I have to stick with APCu.