【问题标题】:How to set a proxy in official Elasticsearch PHP client?如何在官方 Elasticsearch PHP 客户端中设置代理?
【发布时间】:2017-08-15 15:53:12
【问题描述】:

我知道你可以像这样使用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,但是它已经过时并且不适用于当前版本。

【问题讨论】:

    标签: php curl elasticsearch guzzle


    【解决方案1】:

    可能有更简洁的语法,但设置 cURL 参数应该可以:

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

    【讨论】:

    • 成功了!不过请注意,如果您还需要设置代理端口,请使用:'curl' => [ CURLOPT_PROXY => "proxy", CURLOPT_PROXYPORT => "port" ]
    猜你喜欢
    • 1970-01-01
    • 2016-02-20
    • 2012-05-12
    • 1970-01-01
    • 1970-01-01
    • 2017-08-31
    • 2013-01-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多