dpglo66848 2015-11-19 12:07
浏览 99

使用ElasticSearch PHP Client将“cURL错误7”连接到托管的ElasticSearch服务器

Trying to connect to ES hosted with ObjectRocket, but get the following error...

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

My PHP code:

<?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);
?>

But if I run the curl command from the terminal it I have no problem connecting...

curl -XGET http://user:pass@0.es.objectrocket.com:10183
  • 写回答

1条回答 默认 最新

  • duanlinma5885 2016-03-15 13:19
    关注

    I think the package php5-curl extension is missing. If you are using Ubuntu or Linux bases systems,

    sudo apt-get install php5-curl
    

    If you are using nginx, running the above command, would automatically restart php5-fpm, however if you are using apache2, do restart apache2 and php5-fpm

    sudo service apache2 restart
    sudo service php5-fpm restart
    
    评论

报告相同问题?

悬赏问题

  • ¥200 关于#c++#的问题,请各位专家解答!
  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥15 绘制多分类任务的roc曲线时只画出了一类的roc,其它的auc显示为nan
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀