Search by

roadrunner / symfony-lock-driver

roxblnfk

Symfony Lock store backed by the RoadRunner lock plugin: use RoadRunner distributed locks through the symfony/lock API

Package info

github.com/roadrunner-php/symfony-lock-driver

Homepage

Issues

Chat

Forum

Documentation

pkg:composer/roadrunner/symfony-lock-driver

Fund package maintenance!

roadrunner-server

Statistics

Installs: 5

Dependents: 0

Suggesters: 0

Stars: 1

1.3.0 2026-10-10 16:21 UTC

README

RoadRunner

Symfony Lock store backed by the RoadRunner Lock plugin

Documentation Sponsor

Psalm Level Type Coverage codecov Mutation testing badge


This package is a bridge between the RoadRunner Lock plugin and the Symfony Lock component. It provides a RoadRunnerStore, so symfony/lock can manage distributed locks through the RoadRunner server shared by all your workers.

Get Started

Installation

composer require roadrunner/symfony-lock-driver

PHP Latest Version on Packagist License Total Downloads

Configuration

The Lock plugin is driven over RPC, so the RPC plugin must be enabled in .rr.yaml:

version: "3"

rpc:
  listen: tcp://127.0.0.1:6001

Without a lock section the plugin uses the in-memory backend. To share locks between several RoadRunner instances, configure the Redis backend as described in the Lock plugin documentation.

Usage

Create a RoadRunnerStore on top of the RoadRunner Lock client and pass it to the Symfony LockFactory:

use RoadRunner\Lock\Lock;
use Spiral\Goridge\RPC\RPC;
use Spiral\RoadRunner\Symfony\Lock\RoadRunnerStore;
use Symfony\Component\Lock\LockFactory;

require __DIR__ . '/vendor/autoload.php';

$lock = new Lock(RPC::create('tcp://127.0.0.1:6001'));
$factory = new LockFactory(
    new RoadRunnerStore($lock)
);

$invoiceLock = $factory->createLock('invoice-42');

if ($invoiceLock->acquire()) {
    try {
        // ... critical section
    } finally {
        $invoiceLock->release();
    }
}

Read more about using the Symfony Lock component here.

Store options

RoadRunnerStore accepts two timing options:

Option Default Description
$initialTtl 300.0 Default lock time-to-live, in seconds. When it elapses the lock is released automatically; 0 means it never expires on its own.
$initialWaitTtl 0 Default time to wait for the lock to become free, in seconds. 0 is effectively non-blocking: the in-memory backend caps a 0 wait at 1ms (the Redis backend makes a single attempt), so acquiring an already-held lock fails almost immediately. A positive value blocks for up to that duration.
// Wait up to 5 seconds for the lock, and hold it for at most 30 seconds.
$store = (new RoadRunnerStore($lock))->withTtl(ttl: 30.0, waitTtl: 5.0);

Contributing

Contributions are welcome! If you find an issue or have a feature request, please open an issue or submit a pull request.

Credits