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

bool
acquire()

Attempt to acquire the lock.

from  Lock
mixed
get(callable|null $callback = null)

Attempt to acquire the lock.

from  Lock
mixed
block(int $seconds, callable|null $callback = null)

Attempt to acquire the lock for the given number of seconds.

from  Lock
betweenBlockedAttemptsSleepFor(int $milliseconds)

Specify the number of milliseconds to sleep in between blocked lock acquisition attempts.

from  Lock
bool
release()

Release the lock.

from  Lock
string
owner()

Returns the current owner of the lock.

from  Lock
bool
isLocked()

Determine if the lock is currently held by any process.

from  Lock
void
forceRelease()

Releases this lock in disregard of ownership.

from  Lock
bool
refresh(int|null $seconds = null)

Refresh the lock's TTL if still owned by this process.

float|null
getRemainingLifetime()

Get the number of seconds until the lock expires.

Details

in Lock at line 12
bool acquire()

Attempt to acquire the lock.

Return Value

bool

in Lock at line 17
mixed get(callable|null $callback = null)

Attempt to acquire the lock.

Parameters

callable|null $callback

Return Value

mixed

in Lock at line 22
mixed block(int $seconds, callable|null $callback = null)

Attempt to acquire the lock for the given number of seconds.

Parameters

int $seconds
callable|null $callback

Return Value

mixed

in Lock at line 27
Lock betweenBlockedAttemptsSleepFor(int $milliseconds)

Specify the number of milliseconds to sleep in between blocked lock acquisition attempts.

Parameters

int $milliseconds

Return Value

Lock

in Lock at line 32
bool release()

Release the lock.

Return Value

bool

in Lock at line 37
string owner()

Returns the current owner of the lock.

Return Value

string

in Lock at line 42
bool isLocked()

Determine if the lock is currently held by any process.

Return Value

bool

in Lock at line 47
void forceRelease()

Releases this lock in disregard of ownership.

Return Value

void

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.

Parameters

int|null $seconds

Seconds to set the TTL to (null = use original TTL from construction)

Return Value

bool

True if the lock was refreshed (or is permanent and still owned), false if not owned or expired

Exceptions

InvalidArgumentException

at line 42
float|null getRemainingLifetime()

Get the number of seconds until the lock expires.

Return Value

float|null

Seconds remaining, or null if lock doesn't exist or has no expiry