# PHP client not working

**URL:** <https://discuss.elastic.co/t/php-client-not-working/297645>\
**Category:** Elasticsearch\
**Tags:** language-clients\
**Created:** [February 18, 2022, 8:11pm UTC](https://discuss.elastic.co/t/php-client-not-working/297645 "2022-02-18T20:11:17Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![iosif](https://avatars.discourse-cdn.com/v4/letter/i/ccd318/32.png) [@iosif](https://discuss.elastic.co/u/iosif)\
**Post date:** [February 18, 2022, 8:11pm UTC](https://discuss.elastic.co/t/php-client-not-working/297645/1 "2022-02-18T20:11:17Z")

</div>

Hello,  
I want to use the php client. E installed it using Composer, like shown in the tutorial here: [Installation | Elasticsearch PHP Client [7.16] | Elastic](https://www.elastic.co/guide/en/elasticsearch/client/php-api/current/installation.html)

Composer creates the composer.lock file and install the dependencies in the vendor folder.  
However when I try to use the client it doesn't work. For example this code. The first echo is shown but then nothing else, including the second echo. I can make querrys using curl in my terminal so the Elasticsearch is running and I also have an index.

I would be very gratefull for your help. Thank you a lot.

```auto
<?php
echo "test1";
require 'vendor/autoload.php';
$hosts = [
    'https://localhost:9200' 
];

$client = ClientBuilder::create()
                    ->setHosts($hosts)
                    ->build();

$params = [
    'index' => 'my_index',
    'id' => 'my_id',
    'body' => ['testField' => 'abc']
];

$response = $client->index($params);
print_r($response);
echo "test2";
?>
```

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [February 18, 2022, 8:44pm UTC](https://discuss.elastic.co/t/php-client-not-working/297645/2 "2022-02-18T20:44:06Z")

</div>

Is it `https` or `http`?

---

<div class="post-metadata">

**Author:** ![iosif](https://avatars.discourse-cdn.com/v4/letter/i/ccd318/32.png) [@iosif](https://discuss.elastic.co/u/iosif)\
**Post date:** [February 18, 2022, 9:26pm UTC](https://discuss.elastic.co/t/php-client-not-working/297645/3 "2022-02-18T21:26:26Z")

</div>

I now tried with both, makes no difference. Also tried

```auto
$hosts = ['127.0.0.1:9200'];
```

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [February 19, 2022, 12:15am UTC](https://discuss.elastic.co/t/php-client-not-working/297645/4 "2022-02-19T00:15:35Z")

</div>

Could you share the full Elasticsearch logs?

---

<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:** [March 19, 2022, 12:16am UTC](https://discuss.elastic.co/t/php-client-not-working/297645/5 "2022-03-19T00:16:33Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
