<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
diablomedia / guzzle-throttle-middleware example snippets
namespace App\RequestMatcher;
use BenTools\Psr7\RequestMatcherInterface;
use Psr\Http\Message\RequestInterface;
class ExampleOrgRequestMatcher implements RequestMatcherInterface
{
/**
* @inheritDoc
*/
public function matchRequest(RequestInterface $request)
{
return false !== strpos($request->getUri()->getHost(), 'example.org');
}
}
use App\RequestMatcher\ExampleOrgRequestMatcher;
use BenTools\GuzzleHttp\Middleware\Storage\Adapter\ArrayAdapter;
use BenTools\GuzzleHttp\Middleware\ThrottleConfiguration;
use BenTools\GuzzleHttp\Middleware\ThrottleMiddleware;
use GuzzleHttp\Client;
use GuzzleHttp\HandlerStack;
ationInSeconds, 'example')
);
$stack->push($middleware, 'throttle');
$client = new Client([
'handler' => $stack,
]);
$client->get('http://www.example.org'); // Will be executed immediately
$client->get('http://www.example.org'); // Will be executed in 1 second
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.