我正在尝试使用ElasticSearch的托管解决方案,但似乎无法连接到端点。
我一直得到的是以下内容:
Failed to connect to xxx port 9243: Connection refused
这是我的代码...
class ElasticSearchApi {
protected $endpoint;
protected $auth;
protected $curl;
public function __construct() {
$this->endpoint = 'https://myendpoint.com:9243';
$this->auth = 'elastic:pass';
}
public function getIndices() {
$this->curl = curl_init();
curl_setopt($this->curl, CURLOPT_URL, $this->endpoint);
curl_setopt($this->curl, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'accept: application/json', 'Authorization: Basic '. base64_encode($this->auth)));
curl_setopt($this->curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($this->curl, CURLOPT_SSL_VERIFYPEER, false);
$responseData = curl_exec($this->curl);
if(curl_errno($this->curl)) {
return curl_error($this->curl);
}
curl_close($this->curl);
return $responseData;
}
}
答案 0 :(得分:0)
我会首先尝试以下cURL选项:
curl_setopt($ch, CURLOPT_URL,$URL);
curl_setopt($ch, CURLOPT_TIMEOUT, 30); //timeout after 30 seconds
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");
拒绝连接很有趣。如果您在外壳上使用带有curl的细节,那可以正常工作吗?
还有没有特定原因导致您不使用官方PHP client?重试,重新建立连接,...将使您的生活变得更加轻松。