# Keep alive problem

**URL:** <https://discuss.elastic.co/t/keep-alive-problem/93258>\
**Category:** Elasticsearch\
**Created:** [July 15, 2017, 10:46am UTC](https://discuss.elastic.co/t/keep-alive-problem/93258 "2017-07-15T10:46:45Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![henrilabarre](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/henrilabarre/32/16909_2.png) [@henrilabarre](https://discuss.elastic.co/u/henrilabarre)\
**Post date:** [July 15, 2017, 10:46am UTC](https://discuss.elastic.co/t/keep-alive-problem/93258/1 "2017-07-15T10:46:45Z")

</div>

Hi Sometimes when I first connect to eleasticsearch with curl the connexion fails (a timeout problem)...  
After this the second connexion is always successful.

Here is my connextion curl:

```
$curl = curl_init();
$url = "localhost:9200/sirene/_search";
$param = '
	{
		"from" : 0, "size" : 10000,
		"query" : {
			"term" : { "SIREN" : "'.$siren.'" }
		}
	}';

$header = array(
	"content-type: application/x-www-form-urlencoded; charset=UTF-8"
);

$timeout = 2; // in seconds
$timeout2 = 10000; // in milliseconds

curl_setopt_array($curl, array(
  CURLOPT_URL => $url,
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_POSTFIELDS => $param,
  CURLOPT_HTTPHEADER => $header,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_CONNECTTIMEOUT => $timeout,
  CURLOPT_TIMEOUT_MS => $timeout2,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "GET",
  
));

$response = curl_exec($curl);
$err = curl_error($curl);

if ($err) {
     echo "cURL Error #:" . $err;
}

curl_close($curl); 

```

Thanks a lot! I guess this is a problem with a keep alive thing but don't have any clue on this...

---

<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:** [August 12, 2017, 10:47am UTC](https://discuss.elastic.co/t/keep-alive-problem/93258/2 "2017-08-12T10:47:17Z")

</div>

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