API Reference / API Methods / Pass options to the HTTP client
Aug. 06, 2019

Pass options to the HTTP client

The library ships with two HTTP clients:

  • Guzzle6, the most popular HTTP client in the PHP community (recommended)
  • one custom-made http client built on top of curl

In many cases, you may need to pass custom options to the underlying HTTP client, for example to set a proxy configuration.

The PHP client allows you to override what http layer will be used by the SearchClient (and the other clients). You need to set it in the Algolia class before instantiating your client.

You can pass any guzzle option.

1
2
3
4
5
6
7
use Algolia\AlgoliaSearch\Algolia;

$httpClient = new Algolia\AlgoliaSearch\Http\Guzzle6HttpClient([
    'proxy' => $proxyAddress,
]);

Algolia::setHttpClient($httpClient);

Using the default Php53HttpClient

You can pass any curl option.

1
2
3
4
5
6
7
8
use Algolia\AlgoliaSearch\Algolia;

$httpClient = new Algolia\AlgoliaSearch\Http\Php53HttpClient([
    'CURLOPT_PROXY' => $strProxy,
    'CURLOPT_FOLLOWLOCATION' => 1,
]);

Algolia::setHttpClient($httpClient);

Did you find this page helpful?

PHP