Keep alive problem

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...

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