bogkov/concurrency-limit

此组件提供了在服务器上实现并发限制的功能

1.0.0 2017-06-04 22:59 UTC

This package is not auto-updated.

Last update: 2024-09-29 04:25:50 UTC


README

GitHub license Latest Stable Version Minimum PHP Version Build Status codecov Scrutinizer Code Quality

并发限制

此组件提供了在服务器上实现并发限制的功能

安装

此包可以作为Composer依赖安装 bogkov/concurrency-limit

composer require bogkov/concurrency-limit

使用方法

<?php
$provider = new \Bogkov\ConcurrencyLimit\Provider\Cache(new \Doctrine\Common\Cache\ArrayCache());
$handler = new \Bogkov\ConcurrencyLimit\Handler($provider);

$key = 'some-handle-key';
$limit = 1;

if (true === $handler->start($key, $limit)) {
    echo 'continue process' . PHP_EOL;
    $handler->end($key);
} else {
    echo 'concurrency limit exceeded' . PHP_EOL;
}