如何在官方Elasticsearch PHP客户端中设置代理?
我知道您可以使用客户机这样做:如何在官方Elasticsearch PHP客户端中设置代理?,php,curl,
elasticsearch,guzzle,Php,Curl,
elasticsearch,Guzzle,我知道您可以使用客户机这样做: $client = new \Elastica\Client(array( 'host' => 'my host', 'port' => '9200', 'proxy' => 'my proxy' )); 但如果可能的话,我想使用官方客户机。 我已经根据文档建立了连接 但是,文档中没有关于如何设置代理的内容。可能吗 顺便说一句,我已经看到了,但是它已经过时,不能与当前版本一起使用。可能有更简洁的语法,但是设置cURL参数
$client = new \Elastica\Client(array(
'host' => 'my host',
'port' => '9200',
'proxy' => 'my proxy'
));
但如果可能的话,我想使用官方客户机。
我已经根据文档建立了连接
但是,文档中没有关于如何设置代理的内容。可能吗
顺便说一句,我已经看到了,但是它已经过时,不能与当前版本一起使用。可能有更简洁的语法,但是设置cURL参数应该可以:
$client = Elasticsearch\ClientBuilder::create()
->setHosts($hosts)
->setConnectionParams([
'client' => [
'curl' => [
CURLOPT_PROXY => $proxy
]
]
])
->build();
成功了!不过请注意,如果您还需要设置代理端口,请使用:
'curl'=>[CURLOPT\u proxy=>“proxy”,CURLOPT\u PROXYPORT=>“port”]
$client = Elasticsearch\ClientBuilder::create()
->setHosts($hosts)
->setConnectionParams([
'client' => [
'curl' => [
CURLOPT_PROXY => $proxy
]
]
])
->build();