Download the PHP package roadrunner-php/lock without Composer
On this page you can find all versions of the php package roadrunner-php/lock. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download roadrunner-php/lock
More information about roadrunner-php/lock
Files in roadrunner-php/lock
Package lock
Short Description Distributed locks for PHP applications backed by the RoadRunner lock plugin: acquire, release, extend and inspect read and write locks over RPC
License MIT
Homepage https://roadrunner.dev/
Informations about the package lock
Distributed locks for PHP applications powered by RoadRunner
This package is a PHP client for the RoadRunner Lock plugin. It lets your workers acquire, release and manage exclusive and shared (read) locks on named resources, shared across all processes connected to the RoadRunner server.
Get Started
Requirements
Make sure that your server is configured with following PHP version and extensions:
- PHP 8.2+
- RoadRunner 3.0+ with the
lockplugin enabled
Installation
Configuration
The client talks to RoadRunner over RPC, so enable the rpc section in .rr.yaml. The Lock plugin uses the in-memory
backend by default; see the plugin documentation to share locks
between RoadRunner instances through Redis.
Your First Lock
Create a Lock instance with an RPC connection to the RoadRunner server, then acquire and release a lock:
Usage
Acquire lock
Locks a resource so that it can be accessed by one process at a time.
By default the call is non-blocking: if the resource is already locked, it returns false almost immediately
(the RoadRunner server caps the default waitTTL window at 1ms). Pass a positive waitTTL to block until the lock
is released — the call then returns the lock id as soon as the lock becomes free, or false when the waitTTL
timeout elapses.
Acquire read lock
Locks a resource for shared access, allowing multiple processes to access the resource simultaneously. When a resource is locked for shared access, other processes that attempt to lock the resource for exclusive access will fail to do so while any shared lock is held.
As with lock(), the waitTTL parameter is non-blocking by default (false is returned almost immediately, within
the server's 1ms window); pass a positive waitTTL to block for up to that duration for the lock to become available.
Lock parameters
Both lock() and lockRead() accept the same arguments:
| Parameter | Type | Default | Description |
|---|---|---|---|
resource |
non-empty-string |
— | Name of the resource to lock. |
id |
non-empty-string|null |
null |
Lock owner id. When omitted a random UUID is generated. Keep it — the same id must be passed to release(). |
ttl |
int|float|DateInterval |
0 (forever) |
Lock lifetime, in seconds. When it elapses the lock is released automatically; 0 means it never expires on its own. |
waitTTL |
int|float|DateInterval |
0 (~1ms) |
How long to wait for the lock to become free, in seconds. 0 is effectively non-blocking — the server caps it at 1ms, so false is returned almost immediately when the resource is already locked. A positive value blocks for up to that duration, then returns false on timeout. |
Both methods return the lock id (non-empty-string) when the lock is acquired, or false when it is not (the resource stayed busy until the waitTTL window elapsed).
ttlandwaitTTLare expressed in seconds (intorfloat), or as aDateInterval.
Release lock
Releases an exclusive lock or read lock on a resource that was previously acquired by a call to lock()
or lockRead().
Check lock
Checks if a resource is currently locked. Pass a lock id to check whether that particular lock is held.
Update TTL
Updates the time-to-live (TTL) for the locked resource.
Testing
Credits
All versions of lock with dependencies
ramsey/uuid Version ^4.7
roadrunner/api-dto Version ^2.1
roadrunner/goridge Version ^4.5
roadrunner/roadrunner Version ^3.0