PHP Class Elgg\Database\Mutex

Provides database mutex that can be used to prevent race conditions between two processes that affect the same data.
Since: 2.1.0
Show file Open project: elgg/elgg Class Usage Examples

Public Methods

Method Description
__construct ( Database $db, Logger $logger ) Constructor
isLocked ( string $namespace ) : boolean Checks if mutex is locked
lock ( string $namespace ) : boolean Creates a table {prefix}{$namespace}_lock that is used as a mutex.
unlock ( string $namespace ) : void Unlocks mutex

Private Methods

Method Description
assertNamespace ( string $namespace ) : void Assert that the namespace contains only characters [A-Za-z]

Method Details

__construct() public method

Constructor
public __construct ( Database $db, Logger $logger )
$db Elgg\Database Database
$logger Elgg\Logger Logger

isLocked() public method

Checks if mutex is locked
public isLocked ( string $namespace ) : boolean
$namespace string Namespace to use for the database table
return boolean

lock() public method

Creates a table {prefix}{$namespace}_lock that is used as a mutex.
public lock ( string $namespace ) : boolean
$namespace string Allows having separate locks for separate processes
return boolean

unlock() public method

Unlocks mutex
public unlock ( string $namespace ) : void
$namespace string Namespace to use for the database table
return void