Skip to content

f3ath/flock

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Travis Build

Flock. Simple locking mechanism on top of flock()

Usage

$file = '/tmp/my_lock.pid';
$lock = new F3\Flock\Lock($file);

// Non-blocking case. Acquire lock if it's free, otherwse exit immediately
if ($lock->acquire()) {
    // only one instance can reach here
    ...
    // do some job
    ...
    $lock->release();
} else {
    die('Another process is running')
}


// Waiting case. Acquire lock if it's free, otherwse block until it's free and then acquire
if ($lock->acquire(F3\Flock\Lock::BLOCKING)) {
    // only one instance can reach here
    ...
    // do some job
    ...
    $lock->release();
} else {
    // We sould not get to this point in this case
}

About

Simple locking mechanism on top of flock()

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages