如何在官方Elasticsearch PHP客户端中设置代理?

时间:2017-03-23 07:56:43

标签: php curl elasticsearch guzzle

我知道你可以使用Elastica客户端这样做:

$client = new \Elastica\Client(array(
    'host' => 'my host',
    'port' => '9200',
    'proxy' => 'my proxy'
));

但我想尽可能使用官方客户。 我已根据文档here设置了连接。

$hosts = [
    [
    'host' => 'my host',
    'port' => '9200',
    'scheme' => 'http',
    'user' => 'my user',
    'pass' => 'my pass'
    ]
];
$client = Elasticsearch\ClientBuilder::create()
   ->setHosts($hosts)
   ->build();

但是,文档中没有关于如何设置代理的任何内容。可能吗?

顺便说一句,我已经看过this question,但它已经过时,并且不能使用当前版本。

1 个答案:

答案 0 :(得分:3)

可能有更清晰的语法,但设置cURL参数应该有效:

$client = Elasticsearch\ClientBuilder::create()
   ->setHosts($hosts)
    ->setConnectionParams([
        'client' => [
            'curl' => [
                CURLOPT_PROXY => $proxy
            ]
        ]
    ])
   ->build();