class SemaphoreMutex implements MutexInterface (View source)

Traits

Trait that contains stuff that can be useful for Mutexes.

Properties

protected string $temporaryDirectory

The temporary directory.

from  MutexTrait
protected array $semaphores

Methods

setTemporaryDirectory(mixed $temporaryDirectory)

Set the temporary directory.

string
getFilenameForMutexKey(mixed $mutexKey)

Get the full path of a temporary file that's unique for the concrete5 application and for the specified mutex key.

__construct(string $temporaryDirectory)

Initialize the instance.

static bool
isSupported(Application $app)

Is this mutex available for the current system?

acquire(string $key)

Acquire a mutex given its key.

release(string $key)

Release a mutex given its key.

execute(string $key, callable $callback)

Execute a callable by acquiring and releasing a mutex, so that the callable won't be executed by multiple processes concurrently.

Details

protected setTemporaryDirectory(mixed $temporaryDirectory)

Set the temporary directory.

Parameters

mixed $temporaryDirectory

protected string getFilenameForMutexKey(mixed $mutexKey)

Get the full path of a temporary file that's unique for the concrete5 application and for the specified mutex key.

Parameters

mixed $mutexKey

Return Value

string

Exceptions

InvalidMutexKeyException

__construct(string $temporaryDirectory)

Initialize the instance.

Parameters

string $temporaryDirectory

the path to the temporary directory

static bool isSupported(Application $app)

Is this mutex available for the current system?

Parameters

Application $app

Return Value

bool

See also

MutexInterface::isSupported

acquire(string $key)

Acquire a mutex given its key.

If the mutex is already acquired (for example by another process), a.

Parameters

string $key

The identifier of the mutex you want to acquire

Exceptions

InvalidMutexKeyException
MutexBusyException

See also

MutexInterface::acquire

release(string $key)

Release a mutex given its key.

If the mutex not already acquired nothing happens. When the current PHP process ends, the mutex will be released automatically.

Parameters

string $key

The identifier of the mutex you want to release

See also

MutexInterface::release

execute(string $key, callable $callback)

Execute a callable by acquiring and releasing a mutex, so that the callable won't be executed by multiple processes concurrently.

Parameters

string $key

The identifier of the mutex

callable $callback

The callback function to be executed

Exceptions

InvalidMutexKeyException
MutexBusyException

See also

MutexInterface::execute