PHP code example of lightools / bitbang-http-logger
1. Go to this page and download the library: Download lightools/bitbang-http-logger 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/ */
lightools / bitbang-http-logger example snippets
$writer = new Lightools\BitbangLogger\Writers\DefaultWriter(__DIR__ . '/logs/http');
$logger = new Lightools\BitbangLogger\HttpLogger($writer);
$client = new Bitbang\Http\Clients\CurlClient();
$client->onRequest([$logger, 'onRequest']);
$client->onResponse([$logger, 'onResponse']);
$url = 'https://maps.googleapis.com/maps/api/distancematrix/json?origins=Praha&destinations=Brno';
$request = new Bitbang\Http\Request(Bitbang\Http\Request::GET, $url);
try {
$client->process($request);
} catch (Bitbang\Http\BadResponseException $e) {
// process exception
}
$xmlLoader = new Lightools\Xml\XmlLoader();
$arrayDumper = new Lightools\BitbangLogger\ArrayDumper();
$arrayFormatter = new Lightools\BitbangLogger\Formatters\ArrayFormatter($arrayDumper);
$urlFormatter = new Lightools\BitbangLogger\Formatters\UrlEncodedFormatter($arrayDumper);
$jsonFormatter = new Lightools\BitbangLogger\Formatters\JsonFormatter(); // ->registerFormatter($jsonFormatter);
$logger->registerFormatter($xmlFormatter);