尝试连接到使用ObjectRocket托管的ES,但收到以下错误...
Fatal error: Uncaught exception 'Elasticsearch\Common\Exceptions\TransportException' with message 'cURL error 7: See http://curl.haxx.se/libcurl/c/libcurl-errors.html'
in /var/www/html/vendor/elasticsearch/elasticsearch/src/Elasticsearch/Connections/Connection.php:201 Stack trace:
#0 /var/www/html/vendor/react/promise/src/FulfilledPromise.php(25): Elasticsearch\Connections\Connection->Elasticsearch\Connections\{closure}(Array)
#1 /var/www/html/vendor/react/promise/src/Promise.php(114): React\Promise\FulfilledPromise->then(Object(Closure), NULL)
#2 /var/www/html/vendor/react/promise/src/Promise.php(159): React\Promise\Promise->React\Promise\{closure}(Object(React\Promise\FulfilledPromise))
#3 /var/www/html/vendor/react/promise/src/Promise.php(128): React\Promise\Promise->settle(Object(React\Promise\FulfilledPromise))
#4 /var/www/html/vendor/react/promise/src/Promise.php(177): React\Promise\Promise->resolve(Array)
#5 [internal function]: React\Promise\Promise->React\Promise\{closure}(Array)
#6 /var/www/html/vendor/react/pro in /var/www/html/vendor/elasticsearch/elasticsearch/src/Elasticsearch/Connections/Connection.php on line 201
我的PHP代码:
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
require 'vendor/autoload.php';
use Elasticsearch;
use Elasticsearch\ClientBuilder;
$multiHandler = ClientBuilder::multiHandler();
$hosts = [
'http://user:pass@0.es.objectrocket.com:10183',
'http://user:pass@1.es.objectrocket.com:10183',
'http://user:pass@2.es.objectrocket.com:10183',
'http://user:pass@3.es.objectrocket.com:10183'
];
$client = ClientBuilder::create()->setHosts($hosts)->setHandler($multiHandler)->build();
$params = [
'index' => 'my_index',
'type' => 'my_type',
'id' => 'my_id',
'body' => [
'testField' => 'abc'
]
];
$response = $client->index($params);
print_r($response);
?>
但是,如果我从终端运行curl
命令,我连接没问题...
curl -XGET http://user:pass@0.es.objectrocket.com:10183
答案 0 :(得分:0)
我认为缺少包php5-curl
扩展名。
如果您使用的是Ubuntu或Linux基础系统,
sudo apt-get install php5-curl
如果您正在使用nginx,运行上面的命令会自动重启php5-fpm,但是如果您使用的是apache2,请重启apache2和php5-fpm
sudo service apache2 restart
sudo service php5-fpm restart