2

I am curious about where and how PHP stores semaphores in context of sharing them within the application.
From what I was able to understand from documentation, they use shared memory.

Since containers were introduced a few years ago the "use semaphores if you want lock shared within a host" no longer works, or at least I would not trust it to be reliable.

So my questions are:
Where exactly are those semaphores?
Will they be shared between fpm and cli?
Will they work inside a container?
Will they work between containers?
Do I need to share a file using volumes or bind mounts between containers to ensure sharing?
Are there any gotchas when using semaphores in modern systems?

HubertNNN
  • 1,727
  • 1
  • 14
  • 29
  • 2
    I don’t know if it helps, but the PHP functions are just wrappers around the System V IPC functions, and you can explore their documentation here: https://man7.org/linux/man-pages/man7/sysvipc.7.html. They are shared at the OS level, so FPM and CLI should share, and they should work just fine inside a container. – Chris Haas Jan 18 '22 at 08:57
  • As for gotchas, it depends on what you are doing. For me, I almost always need a [simple lock, nothing more complex](https://stackoverflow.com/a/2332868/231316). I almost always use a file system lock, although I have one project where we needed a database-level one. We always use Symfony’s [lock](https://symfony.com/doc/current/components/lock.html) component. – Chris Haas Jan 18 '22 at 09:03

0 Answers0