# Elasticsearch php api is very slow

**URL:** <https://discuss.elastic.co/t/elasticsearch-php-api-is-very-slow/164263>\
**Category:** Elasticsearch\
**Created:** [January 15, 2019, 8:35am UTC](https://discuss.elastic.co/t/elasticsearch-php-api-is-very-slow/164263 "2019-01-15T08:35:43Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![auglkev](https://avatars.discourse-cdn.com/v4/letter/a/b5ac83/32.png) [@auglkev](https://discuss.elastic.co/u/auglkev)\
**Post date:** [January 15, 2019, 8:35am UTC](https://discuss.elastic.co/t/elasticsearch-php-api-is-very-slow/164263/1 "2019-01-15T08:35:43Z")

</div>

I'm using elasticsearch-php api version 6.0 and find it very slow to index or get a document.it always take 7-10 secs to perform a request. However when I'm using raw curl request,it only takes 100ms. I wonder why is this happening. I have already found the code that takes a lot of time to execute but I am not sure how to fix it. The code is listed below, it is located at elasticsearch\elasticsearch\src\Elasticsearch\Connections\Connection.php  
and the code:"$future = $handler($request, $this, $transport, $options);" is the reason for slow  
/\*\*  
\* @param $method  
\* @param $uri  
\* @param null $params  
\* @param null $body  
\* @param array $options  
\* @param \Elasticsearch\Transport $transport  
\* @return mixed  
\*/  
public function performRequest($method, $uri, $params = null, $body = null, $options = , Transport $transport = null)  
{  
if (isset($body) === true) {  
$body = $this-\>serializer-\>serialize($body);  
}

```
    $request = [
        'http_method' => $method,
        'scheme' => $this->transportSchema,
        'uri' => $this->getURI($uri, $params),
        'body' => $body,
        'headers' => array_merge([
            'Host' => [$this->host]
        ], $this->headers)
    ];

    $request = array_replace_recursive($request, $this->connectionParams, $options);

    // RingPHP does not like if client is empty
    if (empty($request['client'])) {
        unset($request['client']);
    }

    $handler = $this->handler;
    $future = $handler($request, $this, $transport, $options);

    return $future;
}
```

---

<div class="post-metadata">

**Author:** ![auglkev](https://avatars.discourse-cdn.com/v4/letter/a/b5ac83/32.png) [@auglkev](https://discuss.elastic.co/u/auglkev)\
**Post date:** [January 15, 2019, 10:12am UTC](https://discuss.elastic.co/t/elasticsearch-php-api-is-very-slow/164263/2 "2019-01-15T10:12:56Z")

</div>

Any help or any other good php api for elasticsearch?

---

<div class="post-metadata">

**Author:** ![randel](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/randel/32/2541_2.png) [@randel](https://discuss.elastic.co/u/randel)\
**Post date:** [January 15, 2019, 2:23pm UTC](https://discuss.elastic.co/t/elasticsearch-php-api-is-very-slow/164263/3 "2019-01-15T14:23:19Z")

</div>

Not sure if that solves your problem, but there is [https://elastica.io/](https://elastica.io/)

---

<div class="post-metadata">

**Author:** ![auglkev](https://avatars.discourse-cdn.com/v4/letter/a/b5ac83/32.png) [@auglkev](https://discuss.elastic.co/u/auglkev)\
**Post date:** [January 16, 2019, 2:21am UTC](https://discuss.elastic.co/t/elasticsearch-php-api-is-very-slow/164263/4 "2019-01-16T02:21:44Z")

</div>

Thx for help,I've tried that however the api documentation is not quite clear

---

<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:** [February 13, 2019, 2:21am UTC](https://discuss.elastic.co/t/elasticsearch-php-api-is-very-slow/164263/5 "2019-02-13T02:21:49Z")

</div>

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