Skip to content
Snippets Groups Projects
Commit 52d880b1 authored by Dominik Hebeler's avatar Dominik Hebeler
Browse files

resetting curl connection on timeout

parent 32f55a0f
No related branches found
No related tags found
No related merge requests found
......@@ -33,6 +33,12 @@ class RequestFetcher extends Command
protected $proxyuser;
protected $proxypassword;
/**
* If we receive an status code 0 in a curl fetch (timeout, etc.) the name of the fetcher (yahoo, adgoal, etc) will get stored
* in this array. And causes the next fetch to establish a fresh connection.
*/
protected $error_connections = [];
/**
* Create a new command instance.
*
......@@ -163,6 +169,12 @@ class RequestFetcher extends Command
$body = \curl_multi_getcontent($info["handle"]);
}
if ($responseCode === 0) {
$this->error_connections[$name] = true;
} else {
$this->error_connections[$name] = false;
}
Redis::pipeline(function ($pipe) use ($resulthash, $body, $cacheDurationMinutes) {
$pipe->lpush($resulthash, $body);
$pipe->expire($resulthash, 60);
......@@ -199,10 +211,17 @@ class RequestFetcher extends Command
CURLOPT_TIMEOUT => 10,
));
if (!empty($job["curlopts"])) {
curl_setopt_array($ch, $job["curlopts"]);
}
if (!empty($this->error_connections[$job["name"]]) && $this->error_connections[$job["name"]] === true) {
Log::info("Using a fresh Curl connection for " . $job["name"]);
curl_setopt($ch, \CURLOPT_FRESH_CONNECT, true);
}
if (!empty($this->proxyhost) && !empty($this->proxyport)) {
curl_setopt($ch, CURLOPT_PROXY, $this->proxyhost);
if (!empty($this->proxyuser) && !empty($this->proxypassword)) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment