https://github.com/f3ath/flock
Simple locking mechanism on top of flock()
https://github.com/f3ath/flock
Last synced: 6 months ago
JSON representation
Simple locking mechanism on top of flock()
- Host: GitHub
- URL: https://github.com/f3ath/flock
- Owner: f3ath
- License: mit
- Created: 2014-02-24T19:36:14.000Z (almost 12 years ago)
- Default Branch: master
- Last Pushed: 2017-10-03T23:04:18.000Z (over 8 years ago)
- Last Synced: 2025-06-02T00:24:58.185Z (7 months ago)
- Language: PHP
- Size: 12.7 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://travis-ci.org/f3ath/flock)
# Flock. Simple locking mechanism on top of flock()
## Usage
```php
$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
}
```