PHP code example of lmammino / guzzle-fs-cache-middleware

1. Go to this page and download the library: Download lmammino/guzzle-fs-cache-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/ */

    

lmammino / guzzle-fs-cache-middleware example snippets




use GuzzleHttp\HandlerStack;
use GuzzleHttp\Handler\CurlHandler;
use GuzzleHttp\Client;
use LM\Guzzle\FS\CacheMiddleware;

$cacheDir = __DIR__.'/cache/';
$namespace = 'api_client';
$ttl = 60;
$cacheMiddleware = new CacheMiddleware($cacheDir, $namespace, $ttl);

$stack = new HandlerStack();
$stack->setHandler(new CurlHandler());
$stack->push($cacheMiddleware);
$client = new Client(['handler' => $stack]);

$res = $client->request('GET', $argv[1]);
$headers = $res->getHeaders();
foreach ($headers as  $k => $h) {
    foreach ($h as $v) {
        echo $k . ": " . $v . "\n";
    }
}
echo "\n\n" . $res->getBody()->__toString() . "\n\n";