# PHP Connection issue with elasticsearch-PHP client, CURL working fine

**URL:** <https://discuss.elastic.co/t/php-connection-issue-with-elasticsearch-php-client-curl-working-fine/52174>\
**Category:** Elasticsearch\
**Created:** [June 8, 2016, 8:26am UTC](https://discuss.elastic.co/t/php-connection-issue-with-elasticsearch-php-client-curl-working-fine/52174 "2016-06-08T08:26:43Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![airper](https://avatars.discourse-cdn.com/v4/letter/a/f9ae1b/32.png) [@airper](https://discuss.elastic.co/u/airper)\
**Post date:** [June 8, 2016, 8:26am UTC](https://discuss.elastic.co/t/php-connection-issue-with-elasticsearch-php-client-curl-working-fine/52174/1 "2016-06-08T08:26:44Z")

</div>

I've been struggling with this for a few days. I initially posted this question on the Elastic Cloud, but they advised to post here.

I have a PHP app running in a Slim2 framework, with Elastic as a  
local installation all working no problems. Elastic PHP client v2 etc  
all configured fine. I'm using a config file to pass connection  
parameters to the Elastic PHP client

Basically I connect to the local cluster with a 'host' = '[http://127.0.0.1:9200](http://127.0.0.1:9200)'  
and set an index with  
'es\_index' =\> ['index' =\> 'test\_index']

This all works fine.

So I setup an Elastic Cloud cluster to trial a production level  
capability. Did that no problem, configured Shield etc, all working.

I can connect to this cluster direct from the server(s) with a simple:

curl -XGET '[http://user:password@b931c39](http://user:password@b931c39)....eu-west-1.aws.found.io:9200/'

**user, password and cluster name not real in above line, but you get the idea.**

That seems to work fine, but if I replace the path in the PHP config file with this endpoint

'path' =\> '[http://user:password@b931c391b4cb](http://user:password@b931c391b4cb)....eu-west-1.aws.found.io:9200'

I get nothing, it essentially cannot find the cluster, even though a cluster and index are present.

So I know I am making a very basic error, but I just can find any  
help, or a decent example. I've tried this from a vagrant box, CURL  
works, PHP doesn't. I've tried it from a Server, same problem.

Can someone point me at some help or an example? I can't see why I  
can connect from any of these servers via CURL, but the path in the  
config file bombs, when it works fine with a local path. I'm assuming  
there is a config issue somewhere that I'm missing?

Thanks Guys

Not sure if this might help, but if I print\_r the $response, I get this with the full end point

Array ( [ok] =\> [message] =\> Unknown cluster.)

If I shorten the end point to - [http://user:password@b931c391b4cb](http://user:password@b931c391b4cb)....eu-west-1.aws:9200

then $response returns

Array ( [error] =\> IndexMissingException[[soros\_test] missing] [status] =\> 404)

So I'm not sure if this is saying the cluster is now found, but the index is unavailable?

Of course if I cut and paste the full endpoint into the browser I get  
the expected response, so I'm assuming this is a configuration issue  
somewhere in elasticsearch-PHP.

Even tried turning on inline scripting but that had no effect.

Completely lost as to what to try next?

The cloud guys have suggested this is probably an issue between the elasticsearch-PHP libs and the Slim2 framework. I'm guessing this is something about the way the URL is being interpreted?

---

<div class="post-metadata">

**Author:** ![danielmitterdorfer](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/danielmitterdorfer/32/110510_2.png) [@danielmitterdorfer](https://discuss.elastic.co/u/danielmitterdorfer)\
**Post date:** [June 14, 2016, 6:47am UTC](https://discuss.elastic.co/t/php-connection-issue-with-elasticsearch-php-client-curl-working-fine/52174/2 "2016-06-14T06:47:41Z")

</div>

Hi @airper,

let me set a few expectations: I know basically nothing about PHP and the Slim2 framework. So I can just give you a couple of generic pointers but I hope this helps you to solve your problem anyway.

I just looked up Slim2 and to me it looks like it cannot really interfere that much with your Elasticsearch configuration. However, can you try to dump down your script to the bare essentials and just get it connect to the cluster?

According to the [PHP client docs](https://www.elastic.co/guide/en/elasticsearch/client/php-api/current/_configuration.html), try to do something along the lines of:

```auto
$hosts = [
    'http://user:password@b931c391b4cb....eu-west-1.aws:9200'
];
$clientBuilder = ClientBuilder::create();
$clientBuilder->setHosts($hosts);
$client = $clientBuilder->build();

// get cluster stats - if the connection is fine, this will work even if you did not create an index
$response = $client->cluster()->stats();

```

If that works, it shows that the PHP client can connect fine and you can iterate from there.

A couple of other suggestions and comments:

- In the beginning you say _"I connect to the local cluster with a **'host'** = '[http://127.0.0.1:9200](http://127.0.0.1:9200)'"_ but then you also say _" **'path'** =\> '[http://user:password@b931c391b4cb](http://user:password@b931c391b4cb)....eu-west-1.aws.found.io:9200'"_. Did you mix up the config parameters and this should actually say **host** instead of **path**?
- You should use HTTPS to encrypt the traffic (HTTPS port is 9243 on Elastic Cloud)
- Inline scripting allows you to use scripts in your queries (see [docs](https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-scripting.html)). So it is not related to your problem and you can turn it off again.

I hope these hints get you on the right track.

Daniel

---

<div class="post-metadata">

**Author:** ![airper](https://avatars.discourse-cdn.com/v4/letter/a/f9ae1b/32.png) [@airper](https://discuss.elastic.co/u/airper)\
**Post date:** [June 14, 2016, 5:55pm UTC](https://discuss.elastic.co/t/php-connection-issue-with-elasticsearch-php-client-curl-working-fine/52174/3 "2016-06-14T17:55:51Z")

</div>

Thanks Daniel, but I think this is an issue with the way the framework renders the URL. Slim is a MVC framework, I think it cannot render the URL structure, which is why this is working with a more basic local URL and not with the remote URL needed by Elastic Cloud.

I'm not sure this is fixable, without development of the framework itself.

I'd be interested to know if Laravel has similar issues with Elastic Cloud?

---

<div class="post-metadata">

**Author:** ![OlivierCoilland](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/oliviercoilland/32/13985_2.png) [@OlivierCoilland](https://discuss.elastic.co/u/OlivierCoilland)\
**Post date:** [February 9, 2017, 4:30pm UTC](https://discuss.elastic.co/t/php-connection-issue-with-elasticsearch-php-client-curl-working-fine/52174/4 "2017-02-09T16:30:12Z")

</div>

Hi, just had a similar issue with Elasticsearch-PHP client and an AWS Elasticsearch cluster.

Endpoint was : [https://search-aaa-abcdefghijklmnopqrstuvwxyz.eu-central-1.es.amazonaws.com](https://search-aaa-abcdefghijklmnopqrstuvwxyz.eu-central-1.es.amazonaws.com)  
(This one is fake but similar)

Trying this failed:

```
$client = ClientBuilder::create()->setHosts([
    'https://search-aaa-abcdefghijklmnopqrstuvwxyz.eu-central-1.es.amazonaws.com'
])->build();
$client->cluster()->stats();

```

But this is working:

```
$client = ClientBuilder::create()->setHosts([
    'https://search-aaa-abcdefghijklmnopqrstuvwxyz.eu-central-1.es.amazonaws.com:443'
])->build();
$client->cluster()->stats();

```

Hope it can help a future-me!

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 5, 2017, 10:03pm UTC](https://discuss.elastic.co/t/php-connection-issue-with-elasticsearch-php-client-curl-working-fine/52174/5 "2017-07-05T22:03:25Z")

</div>


