interface MutexInterface (View source)

Represent a class that can offer a mutually-exclusive system that allows, for instance, to be sure to run some code just once even in concurrent situations.

Methods

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

static bool isSupported(Application $app)

Is this mutex available for the current system?

Parameters

Application $app

Return Value

bool

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

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

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