Skip to content

Instantly share code, notes, and snippets.

@julienbourdeau
Last active December 19, 2018 16:09
Show Gist options
  • Save julienbourdeau/2bdf02bc4e4fc23c084cab89175e9061 to your computer and use it in GitHub Desktop.
Save julienbourdeau/2bdf02bc4e4fc23c084cab89175e9061 to your computer and use it in GitHub Desktop.
Algolia PHP client with Proxy

If you're using a proxy, you can either override the HttpClient or use environment variable.

Setting the HttpClient

If you're using the default Guzzle6HttpClient (recommended):

use Algolia\AlgoliaSearch\Algolia;

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

Algolia::setHttpClient($httpClient);

If you're using the default Php53HttpClient:

use Algolia\AlgoliaSearch\Algolia;

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

Algolia::setHttpClient($httpClient);

Environment variables

Note that this method is only supported by the Guzzle6HttpClient.

Set the HTTPS_PROXY env variable to your secured proxy URL. If some domain should bypass the proxy, you can set them as a comma-separated list in the NO_PROXY env variable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment