Symfony News

New in Symfony 6.1: Configurable Semaphores

Jérémy Derussé

Contributed by
Jérémy Derussé
in #44155.

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:

# config/packages/framework.yaml
framework:
    semaphore: redis://localhost

If your application uses multiple semaphores, configure each of them separately using the same configuration option:

# 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.


Sponsor the Symfony project.


About us

What a Symfony developer should know about the framework: News, Jobs, Tweets, Events, Videos,...

Resources

Find us on Twitter

Find us on Facebook