Skip to content

Latest commit

 

History

History
47 lines (33 loc) · 1.09 KB

http-client.md

File metadata and controls

47 lines (33 loc) · 1.09 KB

Configuring the HTTP client

The Geocoder is decoupled from the HTTP client that sends the HTTP messages. This means that you are responsible for configuring the HTTP client. Usually the default configuration is good enough but sometime you may want to do something differently.

How you configure the client differs between different clients below are two examples, one with Guzzle6 client and one with the cURL client.

Guzzle6

use GuzzleHttp\Client as GuzzleClient;
use Http\Adapter\Guzzle6\Client;
use Geocoder\Provider\GoogleMaps;

$config = [
    'timeout' => 2.0,
    'verify' => false,
];
$guzzle = new GuzzleClient($config);

$adapter  = new Client($guzzle);
$geocoder = new GoogleMaps($adapter);

$geocoder->geocode(...);

cURL

use Http\Client\Curl\Client;
use Geocoder\Provider\GoogleMaps;

$options = [
    CURLOPT_CONNECTTIMEOUT => 2, 
    CURLOPT_SSL_VERIFYPEER => false,
];

$adapter  = new Client(null, null, $options);
$geocoder = new GoogleMaps($adapter);

$geocoder->geocode(...);