geoffroy-aubry/mutex
最新稳定版本:v1.0.1
Composer 安装命令:
composer require geoffroy-aubry/mutex
包简介
Mutex & Semaphore PHP implementations both based only on flock() function.
关键字:
README 文档
README
Mutex & Semaphore PHP implementations both based only on flock() function.
Demo
Mutex
File: demo-mutex.php.
Example:
$oLogger = new MinimalLogger(); $oMutex = new Mutex($oLogger, 100, '/tmp/demo-lock'); $oMutex->acquire(); echo "Do anything for 3 seconds…\n"; sleep(3); $oMutex->release();
⇒ RESULT for 2 processes P1 and P2:
P1 $ php examples/demo-mutex.php Do anything for 3 seconds… P2 $ php examples/demo-mutex.php Waiting to acquire Mutex lock on /tmp/demo-lock… Mutex lock acquired after 2.57s Do anything for 3 seconds…
Semaphore
File: demo-semaphore.php.
Example, semaphore with 2 units of a resource /tmp/demo-sem:
$oLogger = new MinimalLogger(); $oSem = new Semaphore($oLogger, 2, 100, '/tmp/demo-sem'); $oSem->acquire(); echo "Do anything for 3 seconds…\n"; sleep(3); $oSem->release();
⇒ RESULT for 3 processes P1, P2 and P3:
P1 $ php examples/demo-semaphore.php Do anything for 3 seconds… P2 $ php examples/demo-semaphore.php Do anything for 3 seconds… P3 $ php examples/demo-semaphore.php Waiting to acquire lock on /tmp/demo-sem… Lock acquired after 2.30s Do anything for 3 seconds…
Usage
Mutex is available via Packagist.
- Class autoloading and dependencies are managed by Composer so install it following the instructions on Composer: Installation - *nix or just run the following command:
$ curl -sS https://getcomposer.org/installer | php
- Add dependency to
GAubry\Mutexinto require section of yourcomposer.json:
{
"require": {
"geoffroy-aubry/mutex": "1.*"
}
}
and run php composer.phar install from the terminal into the root folder of your project.
- Include Composer's autoloader and use the
GAubry\Mutexclasses.
Copyrights & licensing
Licensed under the GNU Lesser General Public License v3 (LGPL version 3). See LICENSE file for details.
Change log
See CHANGELOG file for details.
Git branching model
The git branching model used for development is the one described and assisted by twgit tool: https://github.com/Twenga/twgit.
统计信息
- 总下载量: 155
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 3
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: LGPL-3.0
- 更新时间: 2015-09-07