class LockHandler

LockHandler class provides a simple abstraction to lock anything by means of a file lock.

A locked file is created based on the lock name when calling lock(). Other lock handlers will not be able to lock the same name until it is released (explicitly by calling release() or implicitly when the instance holding the lock is destroyed).

Methods

__construct(string $name, string|null $lockPath = null)

No description

bool
lock(bool $blocking = false)

Lock the resource.

release()

Release the resource.

Details

at line 40
__construct(string $name, string|null $lockPath = null)

Parameters

string $name The lock name
string|null $lockPath The directory to store the lock. Default values will use temporary directory

Exceptions

IOException If the lock directory could not be created or is not writable

at line 65
bool lock(bool $blocking = false)

Lock the resource.

Parameters

bool $blocking Wait until the lock is released

Return Value

bool Returns true if the lock was acquired, false otherwise

Exceptions

IOException If the lock file could not be created or opened

at line 107
release()

Release the resource.