symfony/semaphore
Symfony Semaphore Component provides semaphores for coordinating access to shared resources across processes and threads. Use it to enforce mutual exclusion, limit concurrency, and prevent race conditions via an easy, reusable API.
symfony/semaphore component remains a robust solution for thread-safe operations in Laravel, with no architectural changes in this beta release. Its abstraction over low-level locking mechanisms (filesystem, Redis, etc.) continues to align well with Laravel’s need for scalable concurrency patterns (e.g., queue jobs, migrations, or critical path operations).Semaphore facade and Symfony’s broader ecosystem remains seamless, reducing friction for teams already leveraging these tools.Semaphore facade remains functional, and the component’s API is stable.Semaphore facade (app('semaphore')) remains functional. Example usage for queue jobs is unchanged:
$semaphore = app('semaphore');
$semaphore->acquire('process_payment_' . $userId, 30);
try {
// Critical section
} finally {
$semaphore->release();
}
$redis = new \Redis();
$redis->connect('redis://redis:6379');
$semaphore = new \Symfony\Component\Semaphore\RedisSemaphore($redis, 'laravel_');
config/semaphore.php can still define Redis DSN and prefix.public function handle(Job $job) {
$semaphore = app('semaphore');
$key = 'job_' . md5($job->payload);
if (!$semaphore->acquire($key, 60)) {
throw new \RuntimeException("Job {$key} is already being processed.");
}
try {
// Process job
} finally {
$semaphore->release();
}
}
symfony/semaphore:^8.1.0-BETA3.php-redis) required for distributed locks; filesystem requires no extensions.HttpClient, Cache).symfony/semaphore:^8.1.0-BETA3 to composer.json.How can I help you explore Laravel packages today?