newclass / claudo
PHP 的信号量系统。
v0.1.0
2018-10-16 09:32 UTC
Requires
- php: >=5.6.0
- ext-json: *
Requires (Dev)
- phpunit/phpunit: ^4.8
This package is auto-updated.
Last update: 2024-09-16 23:24:48 UTC
README
什么是Claudo?
Claudo 是一个 PHP 信号量系统。辅助异步执行代码。
安装
最佳安装方式是使用 composer 通过命令
composer require newclass/claudo
composer install
使用示例
use Claudo\Semaphore;
use Claudo\SemaphoreBatch;
$semaphoreBatch = new SemaphoreBatch();
$semaphoreBatch->add(new Semaphore('test1', '.'));
$semaphoreBatch->add(new Semaphore('test2'));
$result = $semaphoreBatch->synchronize(function (Semaphore $semaphore) {
$var = $semaphore->get('var', null);
if (!$var) {
$var = 0;
}
++$var;
$semaphore->set('var', $var);
return sprintf('finish: %s, result: %d',$semaphore->getName(),$var);
});
echo $result;