SimpleLockStrategy implements LockingStrategyInterface uses BlockSerializationTrait

Simple file locking

Table of Contents

Interfaces

LockingStrategyInterface
Interface for locking methods

Constants

DEFAULT_PRIORITY  = 50
FILE_LOCK_FOLDER  = 'lock/'

Properties

$filePath  : string
$isAcquired  : bool
$loops  : int
$step  : int

Methods

__construct()  : mixed
__destruct()  : mixed
Destructor: Releases lock automatically when instance is destroyed and release resources
__wakeup()  : mixed
Deny object deserialization.
acquire()  : bool
Try to acquire a lock
destroy()  : mixed
Destroys the resource associated with the lock
getCapabilities()  : int
getPriority()  : int
init()  : mixed
isAcquired()  : bool
Get status of this lock
release()  : bool
Release the lock

Constants

DEFAULT_PRIORITY

public mixed DEFAULT_PRIORITY = 50

FILE_LOCK_FOLDER

public mixed FILE_LOCK_FOLDER = 'lock/'

Properties

$filePath

protected string $filePath

File path used for this lock

$isAcquired

protected bool $isAcquired = false

True if lock is acquired

$loops

protected int $loops = 150

Number of times a locked resource is tried to be acquired. Only used in manual locks method "simple".

$step

protected int $step = 200

Milliseconds after lock acquire is retried. $loops * $step results in the maximum delay of a lock. Only used in manual lock method "simple".

Methods

__construct()

public __construct(string $subject) : mixed
Parameters
$subject : string

ID to identify this lock in the system

Tags
throws
LockCreateException

if the lock could not be created

__destruct()

Destructor: Releases lock automatically when instance is destroyed and release resources

public __destruct() : mixed

__wakeup()

Deny object deserialization.

public __wakeup() : mixed

acquire()

Try to acquire a lock

public acquire([int $mode = self::LOCK_CAPABILITY_EXCLUSIVE ]) : bool
Parameters
$mode : int = self::LOCK_CAPABILITY_EXCLUSIVE

LOCK_CAPABILITY_EXCLUSIVE or self::LOCK_CAPABILITY_NOBLOCK

Tags
throws
LockAcquireWouldBlockException
Return values
bool

Returns TRUE if the lock was acquired successfully

destroy()

Destroys the resource associated with the lock

public destroy() : mixed

getCapabilities()

public static getCapabilities() : int
Return values
int

LOCK_CAPABILITY_* elements combined with bit-wise OR

getPriority()

public static getPriority() : int
Return values
int

Returns a priority for the method. 0 to 100, 100 is highest

init()

public init([int $loops = 0 ][, int $step = 0 ]) : mixed
Parameters
$loops : int = 0

Number of times a locked resource is tried to be acquired.

$step : int = 0

Milliseconds after lock acquire is retried. $loops * $step results in the maximum delay of a lock.

isAcquired()

Get status of this lock

public isAcquired() : bool
Return values
bool

Returns TRUE if lock is acquired by this locker, FALSE otherwise

release()

Release the lock

public release() : bool
Return values
bool

Returns TRUE on success or FALSE on failure


        
On this page

Search results