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

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




uzzleHttp\HandlerStack;
use GuzzleHttp\Handler\CurlHandler;
use GuzzleHttp\Client;
use Kevinrob\GuzzleCache\CacheMiddleware;
use Kevinrob\GuzzleCache\Strategy\PrivateCacheStrategy;
use LM\GuzzleCache\Storage\ApcuFsStorage;

// creates the storage (with default options)
$cacheStorage = new ApcuFsStorage();

// creates the cache middleware
$cacheMiddleware = new CacheMiddleware(
    new PrivateCacheStrategy($cacheStorage)
);

// creates a Guzzle client middleware stack
$stack = new HandlerStack();
$stack->setHandler(new CurlHandler());
$stack->push($cacheMiddleware, 'cache');
$client = new Client(['handler' => $stack]);

// make a request
$res = $client->request('GET', 'https://loige.co/');
// print response headers
$headers = $res->getHeaders();
foreach ($headers as  $k => $h) {
    foreach ($h as $v) {
        echo $k . ": " . $v . "\n";
    }
}
// print response body
echo "\n\n" . $res->getBody()->__toString() . "\n\n";



aunchDarkly\LDClient;
use LaunchDarkly\LDUser;
use LM\GuzzleCache\Storage\ApcuFsStorage;

$cacheStorage = new ApcuFsStorage();
$LDClient = new LDClient($ldSDKKey, ["cache" => $cacheStorage]);
$LDUser = new LDUser("[email protected]");

// use the client
var_dump($LDClient->variation('some-flag', $LDUser));