设置elasticsearch php客户端的connect_timeout [英] set connect_timeout of elasticsearch php client

查看:841
本文介绍了设置elasticsearch php客户端的connect_timeout的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的elasticsearch php客户端到我的弹性搜索服务器之间配置一个小的超时。



我试图将一些参数传递给guzzle客户端,但似乎这不行
这里是代码:

  $ params = array(); 
$ params ['hosts'] = $ hosts;
$ params ['guzzleOptions'] ['connect_timeout'] = 2.0;
$ params ['guzzleOptions'] ['timeout'] = 2.0;
$ this-> elastica_obj = new Elasticsearch\Client($ params);

我搜索并发现问题可能会发生,因为超时在cURL层(即低于guzzle)
使用Guzzle HTTP限制连接时间PHP客户端



我想我需要某种方式将CURLOPT_CONNECTTIMEOUT_MS参数设置为我想要的值(2000ms),但是我没有看到任何好的方式通过它通过弹性搜索php客户端。



有人知道如何做吗?

解决方案

谢谢Zack,
我尝试了,但它不起作用。



我调试了客户端和参数传递的方式



我找到完成它的方式是将此参数传递给Elasticsearch客户端

  $ params ['guzzleOptions'] ['curl.options'] [CURLOPT_CONNECTTI MEOUT] = 2.0; //这适用2秒connection_timeout 

希望它正在帮助:)



Niv


i want to configure a a small timeout between my elasticsearch php client to the my elasticsearch server.

i tried to pass some parameters to the guzzle client but it seems this doesn't work. here is the code:

$params = array();
$params['hosts'] = $hosts;
$params['guzzleOptions']['connect_timeout'] = 2.0;
$params['guzzleOptions']['timeout'] = 2.0;
$this->elastica_obj = new Elasticsearch\Client($params);

i searched and found that the problem might occured because the timeout is set in the cURL layer (that is lower than the guzzle) (Limit connecting time with Guzzle HTTP PHP client)

i guess i need somehow to set CURLOPT_CONNECTTIMEOUT_MS parameter to the value i want (2000ms) but i don't see any good way to pass it through the elasticsearch php client.

Does someone knows how to do it?

解决方案

Thanks Zack, I tried it but it doesn't work.

I debugged the client and the way the parameters are being pass from through the guzzle to the curl handle.

the way i find to accomplish it is to pass this parameter to the Elasticsearch client

$params['guzzleOptions']['curl.options'][CURLOPT_CONNECTTIMEOUT] = 2.0;  // this applies 2 seconds connection_timeout

hope it is helping :)

Niv

这篇关于设置elasticsearch php客户端的connect_timeout的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆