PHP code example of slepic / http-transfer

1. Go to this page and download the library: Download slepic/http-transfer 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/ */

    

slepic / http-transfer example snippets


$storage = new ArrayStorage();
$storage->store(new Log($request, $start, $end, $response, $exception, $context));
assert($storage[0]->getRequest() === $request);
assert($storage[0]->getResponse() === $response);
assert($storage[0]->getException() === $exception);
assert($storage[0]->getStartTime() === $start);
assert($storage[0]->getEndTime() === $end);
assert($storage[0]->getContext() === $context);

//create services
$storage = new ArrayStorage();
$observer = new HistoryObserver($storage);


//somewhere you send some requests
foreach ($requests as $request) {his 
  $delegate = $observer->observe($request);
  try {
    $response = $client->sendRequest($request);
  } catch (\Exception $e) {
    $delegate->error($e);
    throw $e;
  }
  $delegate->success($response);
}


//and when u need it you can access transfer logs
foreach ($storage as $log) {
  var_dump($log->getRequest());
  var_dump($log->getResponse());
  var_dump($log->getEndTime() - $log->getStartTime());
  //...
}