Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Semaphore Laravel Package

symfony/semaphore

The Symfony Semaphore Component manages semaphores, a mechanism that provides exclusive access to a shared resource. It is a standalone PHP library you can use in any project to coordinate concurrent processes and prevent race conditions.

View on GitHub
Deep Wiki
Context7

Symfony Semaphore Component

Frequently asked questions about Semaphore
How do I install symfony/semaphore in a Laravel application?
Install the package with Composer using composer require symfony/semaphore. Laravel can resolve SemaphoreInterface through the container once you bind a concrete backend such as RedisSemaphore. For Redis you typically also need predis/predis or a working phpredis extension. No Laravel-specific service provider is shipped, so registration is manual.
Is symfony/semaphore compatible with Laravel 10 and 11?
Yes for typical modern stacks: full compatibility needs PHP 8.1+ for Symfony 6.4+ and Laravel 10+. The component itself is framework-agnostic and integrates through Laravel's Symfony components and container. Older Laravel or PHP versions may need version constraints or polyfills.
How can I use symfony/semaphore to stop duplicate Laravel queue jobs?
Inject or resolve SemaphoreInterface in the job and acquire a named semaphore before the critical section. Use acquire with a timeout, run the work, and release in a finally block. This serializes workers so only one process handles the shared resource at a time. For distributed queues, use the Redis backend.
Should I use Redis or filesystem locks with Symfony Semaphore in Laravel?
Use Redis for multi-process and distributed Laravel environments such as queue workers and cron jobs. Filesystem locks are fine for single-process or single-host setups but do not coordinate across servers. The component supports both, and RedisSemaphore is the recommended choice for most production Laravel apps.
How do I bind SemaphoreInterface in Laravel's AppServiceProvider?
Register a singleton in AppServiceProvider's register method that returns a RedisSemaphore using a Laravel Redis connection. Resolve SemaphoreInterface from the container in jobs, services, or middleware. This keeps lock configuration centralized and testable. You can also bind a filesystem semaphore for local development.
How do I prevent deadlocks when using semaphores in Laravel queue jobs?
Always release acquired semaphores in a finally block so exceptions and job retries do not leave locks held. Use short, bounded acquire timeouts rather than waiting indefinitely. Keep critical sections small and avoid nesting multiple semaphores where possible. Idempotent job design and monitoring help catch stuck locks.
Does symfony/semaphore support Redis Cluster or Relay?
The component supports Relay\Cluster from v7.3+, which improves scalability for Redis cluster setups. For Laravel apps using Redis Cluster, confirm your Symfony Semaphore version and Redis client configuration. Predis or phpredis support depends on the connection you pass to RedisSemaphore. Test failover behavior before relying on it in production.
What is the performance overhead of Symfony Semaphore locks in Laravel?
Redis-backed semaphore operations typically add about 1 to 10 ms per lock operation due to network round-trips. Filesystem locks avoid network latency but do not coordinate across hosts. For high-throughput systems above roughly 10K requests per second, benchmark acquire and release paths. Keep lock scope narrow to limit overhead.
Which Symfony Semaphore version should I use with Laravel?
Pin an actively supported line that matches your Laravel and PHP versions; modern Laravel 10+ stacks generally target Symfony 6.4 or 7.x/8.x. Be careful with the v5.4.54 security release because it is a different maintenance branch from v8.1.0-BETA3. Confirm that any security fix is present in the line you actually deploy. Symfony 5.4 is past end of security support and should be treated as a migration forcing function.
Can symfony/semaphore be used for API rate limiting in Laravel?
Yes, it can back a custom Laravel middleware that acquires a named semaphore per API key or route before allowing the request through. It is a locking primitive rather than a full rate limiter, so you must implement counters, time windows, and response handling yourself. Laravel's built-in RateLimiter may be simpler for standard throttling, while semaphores suit exclusive-access constraints.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
elmogy/larafast
xeviant/laravel-paystack
gorilladash/laravel-website-sdk
martialbe/flysystem-oss
chondal/3312client
jeroen-g/flickr
opscale-co/nova-genbi
itsjustvita/laravel-retention
tequilarapido/trackit
gregsphotography/site-builder-filament
cabaoctavio/laravel-query-log
gregsphotography/site-builder-components
io-digital/clickatell
snowsoft/laravel-admin
oxygen/auth
relicsoftware/barakah-payment-gateway
tobya/work-with-composer
equipc/laravel-email-validator
equipc/laravel-email-database-log
adedsec/nova-translated-labels