RefreshableLock
interface RefreshableLock implements Lock
A lock that supports refreshing its TTL and inspecting remaining lifetime.
Not all lock drivers can implement this interface atomically. Drivers that cannot guarantee atomic refresh operations (like CacheLock) should not implement this interface.
Methods
Attempt to acquire the lock for the given number of seconds.
Specify the number of milliseconds to sleep in between blocked lock acquisition attempts.
Refresh the lock's TTL if still owned by this process.
Get the number of seconds until the lock expires.
Details
in
Lock at line 12
bool
acquire()
Attempt to acquire the lock.
in
Lock at line 17
mixed
get(callable|null $callback = null)
Attempt to acquire the lock.
in
Lock at line 22
mixed
block(int $seconds, callable|null $callback = null)
Attempt to acquire the lock for the given number of seconds.
in
Lock at line 27
Lock
betweenBlockedAttemptsSleepFor(int $milliseconds)
Specify the number of milliseconds to sleep in between blocked lock acquisition attempts.
in
Lock at line 32
bool
release()
Release the lock.
in
Lock at line 37
string
owner()
Returns the current owner of the lock.
in
Lock at line 42
bool
isLocked()
Determine if the lock is currently held by any process.
in
Lock at line 47
void
forceRelease()
Releases this lock in disregard of ownership.
at line 35
bool
refresh(int|null $seconds = null)
Refresh the lock's TTL if still owned by this process.
This operation is atomic - if the lock has been released or acquired by another process, this will return false without modifying anything.
When called without arguments, the TTL is re-applied exactly as the driver interpreted the acquisition duration: drivers with native expiry treat a lock acquired with a TTL of 0 as permanent and only verify ownership, while drivers without native expiry re-extend their default safety timeout.
at line 42
float|null
getRemainingLifetime()
Get the number of seconds until the lock expires.