PHP code example of vectorifyai / guzzle-rate-limiter
1. Go to this page and download the library: Download vectorifyai/guzzle-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/ */
vectorifyai / guzzle-rate-limiter example snippets
use GuzzleHttp\Client;
use GuzzleHttp\HandlerStack;
use Vectorify\GuzzleRateLimiter\RateLimiterMiddleware;
use Vectorify\GuzzleRateLimiter\Stores\InMemoryStore;
$stack = HandlerStack::create();
$stack->push(new RateLimiterMiddleware(new InMemoryStore));
$client = new Client([
'handler' => $stack,
]);
use Vectorify\GuzzleRateLimiter\RateLimiterMiddleware;
use Vectorify\GuzzleRateLimiter\Stores\InMemoryStore;
$middleware = new RateLimiterMiddleware(new InMemoryStore);
use Vectorify\GuzzleRateLimiter\Stores\LaravelStore;
$store = new LaravelStore(cache(), 'api:rate_limit');
$middleware = new RateLimiterMiddleware($store);
use Vectorify\GuzzleRateLimiter\Stores\SymfonyStore;
use Symfony\Component\Cache\Adapter\RedisAdapter;
$cache = new RedisAdapter(/* redis client */);
$store = new SymfonyStore($cache, 'api:rate_limit');
$middleware = new RateLimiterMiddleware($store);
use Vectorify\GuzzleRateLimiter\Stores\FilesystemStore;
use League\Flysystem\Local\LocalFilesystemAdapter;
// Local filesystem
$adapter = new LocalFilesystemAdapter('/path/to/cache');
$store = new FilesystemStore($adapter);
$middleware = new RateLimiterMiddleware($store);
// AWS S3
use League\Flysystem\AwsS3V3\AwsS3V3Adapter;
$s3Adapter = new AwsS3V3Adapter($s3Client, $bucket, $prefix);
$store = new FilesystemStore($s3Adapter);
// SFTP
use League\Flysystem\PhpseclibV3\SftpAdapter;
$sftpAdapter = new SftpAdapter(/* SFTP connection settings */);
$store = new FilesystemStore($sftpAdapter);
$middleware = new RateLimiterMiddleware(
store: new InMemoryStore,
cachePrefix: 'my_api:rate_limit',
logger: $customLogger,
);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.