Documentation

Lock
in package

Lock class for PHP scripts Create a lock file in "<basePath>/processName.lock", containing the script PID, and the maxLife (in minutes) for the process. When script is called it search for the lock file and: - if not exists, it is created - if exists but is expired (creationTime filectime + $this->maxLifeInMin*60 > NOW), kill the previuos PID, destroy and recreate lock - if exists and is not expired, simply dont acquire the lock

Table of Contents

Properties

$acquired  : bool
$filepath  : string
$killedFrozenProcess  : bool
$maxLifeInMin  : int
$path  : string

Methods

__construct()  : mixed
acquired()  : bool
Get lock acquire status
filepath()  : string
Get filepath url
haveYouKilledFrozenProcess()  : bool
Get status about previuos process killed
release()  : bool
Get status lock release
isKilledFrozenProcess()  : bool
Kill frozen process
isToKill()  : bool
Check if previous executed process is to kill
mkLock()  : bool
Create lock file containing process PID
mkPath()  : bool
Create path dir for lock files Check if file exists AND is directory AND is writable, or try to create/set it permission

Properties

$acquired

private bool $acquired = false

$filepath

private string $filepath

$killedFrozenProcess

private bool $killedFrozenProcess = false

$maxLifeInMin

private int $maxLifeInMin = 30

$path

private string $path

Methods

__construct()

public __construct(string $processName[, string|null $basePath = './' ][, int|null $maxLifeInMin = 30 ]) : mixed
Parameters
$processName : string
$basePath : string|null = './'
$maxLifeInMin : int|null = 30

acquired()

Get lock acquire status

public acquired() : bool
Return values
bool

True if is acquired, false otherwise

filepath()

Get filepath url

public filepath() : string
Return values
string

lock file path

haveYouKilledFrozenProcess()

Get status about previuos process killed

public haveYouKilledFrozenProcess() : bool
Return values
bool

True if is killed, false otherwise

release()

Get status lock release

public release() : bool
Return values
bool

True if is released, false otherwise

isKilledFrozenProcess()

Kill frozen process

private isKilledFrozenProcess() : bool
Return values
bool

True when process is killed, false otherwise

isToKill()

Check if previous executed process is to kill

private isToKill() : bool
Return values
bool

True if is to kill, false otherwise

mkLock()

Create lock file containing process PID

private mkLock() : bool
Return values
bool

True if file exists AND is directory AND is writable, false otherwise

mkPath()

Create path dir for lock files Check if file exists AND is directory AND is writable, or try to create/set it permission

private mkPath(string $path) : bool
Parameters
$path : string

Path to try to create

Return values
bool

True if file exists AND is directory AND is writable, false otherwise


        
On this page

Search results