PHP code example of emanueleminotto / guzzle-snapshot
1. Go to this page and download the library: Download emanueleminotto/guzzle-snapshot 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/ */
emanueleminotto / guzzle-snapshot example snippets
use EmanueleMinotto\GuzzleSnapshot\Strategy\ReadableFileStrategy;
use GuzzleHttp\Client;
use GuzzleHttp\HandlerStack;
// use Doctrine\Common\Cache\ArrayCache;
// use EmanueleMinotto\GuzzleSnapshot\Strategy\DoctrineCacheStrategy;
// $strategy = new DoctrineCacheStrategy(new ArrayCache());
$strategy = new ReadableFileStrategy(__DIR__.'/__snapshots__');
$middleware = new SnapshotMiddleware($strategy);
// $middleware->setRequestStorage(true); // this will save requests too
$stack = HandlerStack::create();
$stack->push($middleware);
$client = new Client([
'handler' => $this->stack,
]);
// if the response file was already stored in
// the directory __snapshots___, this request wont
// be sent to the remote endpoint
$client->get('http://www.example.com/');
// this request wont be sent in any case
$client->get('http://www.example.com/');