abstract class Lock implements Lock

Traits

Properties

protected string $name

The name of the lock.

protected int $seconds

The number of seconds the lock should be maintained.

protected string $owner

The scope identifier of this lock.

protected int $sleepMilliseconds

The number of milliseconds to wait before re-attempting to acquire a lock while blocking.

Methods

int
secondsUntil(DateInterval|DateTimeInterface|int $delay)

Get the number of seconds until the given DateTime.

int
availableAt(DateInterval|DateTimeInterface|int|null $delay = 0)

Get the "available at" UNIX timestamp.

parseDateInterval(DateInterval|DateTimeInterface|int|null $delay)

If the given value is an interval, convert it to a DateTime instance.

int
currentTime()

Get the current system time as a UNIX timestamp.

string
runTimeForHumans(float $startTime, float|null $endTime = null)

Given a start time, format the total run time for human readability.

__construct(string $name, int $seconds, string|null $owner = null)

Create a new lock instance.

bool
acquire()

Attempt to acquire the lock.

bool
release()

Release the lock.

string|null
getCurrentOwner()

Return the owner value written into the driver for this lock.

mixed
get(callable|null $callback = null)

Attempt to acquire the lock.

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

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

bool
refresh(int|null $seconds = null)

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

float|null
getRemainingLifetime()

Get the number of seconds until the lock expires.

string
owner()

Return the current owner of the lock.

bool
isLocked()

Determine if the lock is currently held by any process.

bool
isOwnedByCurrentProcess()

Determine whether this lock is allowed to release the lock in the driver.

bool
isOwnedBy(string|null $owner)

Determine whether this lock is owned by the given identifier.

betweenBlockedAttemptsSleepFor(int $milliseconds)

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

Details

in InteractsWithTime at line 17
protected int secondsUntil(DateInterval|DateTimeInterface|int $delay)

Get the number of seconds until the given DateTime.

Parameters

DateInterval|DateTimeInterface|int $delay

Return Value

int

in InteractsWithTime at line 29
protected int availableAt(DateInterval|DateTimeInterface|int|null $delay = 0)

Get the "available at" UNIX timestamp.

Parameters

DateInterval|DateTimeInterface|int|null $delay

Return Value

int

in InteractsWithTime at line 41
protected DateTimeInterface|int parseDateInterval(DateInterval|DateTimeInterface|int|null $delay)

If the given value is an interval, convert it to a DateTime instance.

Parameters

DateInterval|DateTimeInterface|int|null $delay

Return Value

DateTimeInterface|int

in InteractsWithTime at line 57
protected int currentTime()

Get the current system time as a UNIX timestamp.

Return Value

int

in InteractsWithTime at line 65
protected string runTimeForHumans(float $startTime, float|null $endTime = null)

Given a start time, format the total run time for human readability.

Parameters

float $startTime
float|null $endTime

Return Value

string

at line 44
__construct(string $name, int $seconds, string|null $owner = null)

Create a new lock instance.

Parameters

string $name
int $seconds
string|null $owner

at line 58
abstract bool acquire()

Attempt to acquire the lock.

Return Value

bool

at line 63
abstract bool release()

Release the lock.

Return Value

bool

at line 68
abstract protected string|null getCurrentOwner()

Return the owner value written into the driver for this lock.

Return Value

string|null

at line 73
mixed get(callable|null $callback = null)

Attempt to acquire the lock.

Parameters

callable|null $callback

Return Value

mixed

at line 101
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

Exceptions

LockTimeoutException

at line 143
bool refresh(int|null $seconds = null)

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

Parameters

int|null $seconds

Return Value

bool

Exceptions

RuntimeException

at line 153
float|null getRemainingLifetime()

Get the number of seconds until the lock expires.

Return Value

float|null

Exceptions

RuntimeException

at line 161
string owner()

Return the current owner of the lock.

Return Value

string

at line 169
bool isLocked()

Determine if the lock is currently held by any process.

Return Value

bool

at line 177
bool isOwnedByCurrentProcess()

Determine whether this lock is allowed to release the lock in the driver.

Return Value

bool

at line 185
bool isOwnedBy(string|null $owner)

Determine whether this lock is owned by the given identifier.

Parameters

string|null $owner

Return Value

bool

at line 193
Lock betweenBlockedAttemptsSleepFor(int $milliseconds)

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

Parameters

int $milliseconds

Return Value

Lock