PHP code example of bmancone / guzzle-stopwatch-middleware
1. Go to this page and download the library: Download bmancone/guzzle-stopwatch-middleware 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/ */
bmancone / guzzle-stopwatch-middleware example snippets
use GuzzleHttp\Client;
use GuzzleHttp\HandlerStack;
use GuzzleHttp\Psr7\Request;
use Symfony\Component\Stopwatch\Stopwatch;
Use Leadz\GuzzleHttp\Stopwatch\StopwatchMiddleware;
// Create the default HandlerStack
$stack = HandlerStack::create();
// Create the middleware
$middleware = new StopwatchMiddleware(new Stopwatch());
// Push the Middleware to the stack
$stack->push($middleware);
// Create the client
$client = new Client([
'handler' => $stack
]);
// Send the request
$request = new Request('GET', 'https://en.wikipedia.org/wiki/Main_Page');
$response = $client->send($request);
// Get the duration of the request
printf('Request to [%s] took [%dms]', (string)$request->getUri(), $response->getHeaderLine('X-Duration'));