Lock
Grab a named lock backed by the database, run a callback while it is held, and release it when the callback finishes. While one process holds a named lock, no other process can take the same name.
This page is a pure reference. For how the framework fits together, see the Guide.
LockDatabase- grab a named database lock and run a callback while it is held.
LockDatabase
Grab a lock with a given name and call the callback once it is held. The lock is removed when the callback finishes, whether it returns or throws. Grabbing is retried a number of times with a growing, randomised wait between attempts, so that many processes competing for the same lock spread their retries out over time.
Constants
| Constant | Value | Description |
|---|---|---|
LockDatabase::RETRIES | 8 | Number of times to try to grab a lock if it fails. |
LockDatabase::TIMEOUT_MILLISECONDS | 10 | Initial wait between attempts to grab a lock; it doubles on every retry. |
Grab
LockDatabase::Grab(string $name, Callable $onSuccess)
Grab a lock and call the callback when the lock is grabbed. The lock is removed when the callback finishes, whether it returns or throws. On success returns whatever the callback returns. Throws DatabaseError when the lock cannot be grabbed within the retries.
| Name | Type | Description |
|---|---|---|
$name | string | The name of the lock to grab. |
$onSuccess | Callable | The callback to run while the lock is held; only called once the lock is grabbed. |
Returns mixed Whatever the callback returns.