In Symfony 5.2 we introduced a Semaphore component as an alternative to the existing Lock component. According to the Wikipedia definition, a semaphore is a variable or abstract data type used to control access to a common resource by multiple processes in a concurrent system such as a multitasking operating system. Broadly speaking, a semaphore allows N process to access a resource, and a lock is a semaphore where N = 1.
In Symfony 6.1 we're improving Semaphore integration in Symfony applications
thanks to the new framework.semaphore
option. First, you can pass a string
with the DSN of the store used by the semaphore:
1 2 3
# config/packages/framework.yaml
framework:
semaphore: redis://localhost
If your application uses multiple semaphores, configure each of them separately using the same configuration option:
1 2 3 4 5
# config/packages/framework.yaml
framework:
semaphore:
invoices: redis://localhost/1
orders: redis://localhost/2
That's all! Symfony will create the configured semaphore(s) and will make them available to your application.