API Reference
/
API Methods
/
Pass options to the HTTP client
Jul. 31, 2020
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.
Using the default Guzzle6HttpClient
(recommended)
You can pass any guzzle option.
Copy
1
2
3
4
5
6
7
8
9
10
use Algolia\AlgoliaSearch\Algolia;
use GuzzleHttp\Client as GuzzleClient;
$httpClient = new Algolia\AlgoliaSearch\Http\Guzzle6HttpClient(
new GuzzleClient([
'proxy' => $proxyAddress,
])
);
Algolia::setHttpClient($httpClient);
Using the default Php53HttpClient
You can pass any curl option.
Copy
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);