PHP Class yii\mutex\Mutex

This is achieved by using a "lock" mechanism. Each possibly concurrent thread cooperates by acquiring a lock before accessing the corresponding data. Usage example: if ($mutex->acquire($mutexName)) { business logic execution } else { execution is blocked! } This is a base class, which should be extended in order to implement the actual lock mechanism.
Since: 2.0
Author: resurtm ([email protected])
Inheritance: extends yii\base\Component
显示文件 Open project: yiisoft/yii2 Class Usage Examples

Public Properties

Property Type Description
$autoRelease whether all locks acquired in this process (i.e. local locks) must be released automatically before finishing script execution. Defaults to true. Setting this property to true means that all locks acquired in this process must be released (regardless of errors or exceptions).

Public Methods

Method Description
acquire ( string $name, integer $timeout ) : boolean Acquires a lock by name.
init ( ) Initializes the Mutex component.
release ( string $name ) : boolean Releases acquired lock. This method will return false in case the lock was not found.

Protected Methods

Method Description
acquireLock ( string $name, integer $timeout ) : boolean This method should be extended by a concrete Mutex implementations. Acquires lock by name.
releaseLock ( string $name ) : boolean This method should be extended by a concrete Mutex implementations. Releases lock by given name.

Method Details

acquire() public method

Acquires a lock by name.
public acquire ( string $name, integer $timeout ) : boolean
$name string of the lock to be acquired. Must be unique.
$timeout integer time to wait for lock to be released. Defaults to zero meaning that method will return false immediately in case lock was already acquired.
return boolean lock acquiring result.

acquireLock() abstract protected method

This method should be extended by a concrete Mutex implementations. Acquires lock by name.
abstract protected acquireLock ( string $name, integer $timeout ) : boolean
$name string of the lock to be acquired.
$timeout integer time to wait for the lock to be released.
return boolean acquiring result.

init() public method

Initializes the Mutex component.
public init ( )

release() public method

Releases acquired lock. This method will return false in case the lock was not found.
public release ( string $name ) : boolean
$name string of the lock to be released. This lock must already exist.
return boolean lock release result: false in case named lock was not found..

releaseLock() abstract protected method

This method should be extended by a concrete Mutex implementations. Releases lock by given name.
abstract protected releaseLock ( string $name ) : boolean
$name string of the lock to be released.
return boolean release result.

Property Details

$autoRelease public_oe property

whether all locks acquired in this process (i.e. local locks) must be released automatically before finishing script execution. Defaults to true. Setting this property to true means that all locks acquired in this process must be released (regardless of errors or exceptions).
public $autoRelease