PHP code example of dnomyar / php-rate-limiter
1. Go to this page and download the library: Download dnomyar/php-rate-limiter library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
dnomyar / php-rate-limiter example snippets
use Dnomyar\PhpFileSystemRateLimiter\Domain\RateLimiter;
use Dnomyar\PhpFileSystemRateLimiter\Domain\Model\Configuration\BucketSize;
use Dnomyar\PhpFileSystemRateLimiter\Domain\Model\Configuration\BucketTime;
use Dnomyar\PhpFileSystemRateLimiter\Domain\Model\Configuration\Duration;
use Dnomyar\PhpFileSystemRateLimiter\Infrastructure\Repository\LockFileImplementation;
use Dnomyar\PhpFileSystemRateLimiter\Infrastructure\Repository\BucketSerializerImplementation;
use Dnomyar\PhpFileSystemRateLimiter\Infrastructure\Repository\FileSystemFileAdapterImplementation;
use Dnomyar\PhpFileSystemRateLimiter\Infrastructure\Repository\FileSystemBucketRepository;
$rateLimiter = new RateLimiter(
new BucketTime(Duration::seconds(10)),
BucketSize::createBucketSize(6),
new FileSystemBucketRepository(
new FileSystemFileAdapterImplementation(),
new BucketSerializerImplementation(),
new LockFileImplementation()
)
);
/*
* return true of false if the call is allowed
* thows a BucketRepositoryException if another request is trying to use the feature at the same time.
*/
$rateLimiter->allowCall('id-to-change');