Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 14 additions & 13 deletions lib/Segment/Consumer/LibCurl.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,38 +84,39 @@ public function flushBatch($messages) {
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

// retry failed requests just once to diminish impact on performance
$httpResponse = $this->executePost($ch);
$responseContent = curl_exec($ch);

$err = curl_error($ch);
if ($err) {
$this->handleError(curl_errno($ch), $err);
return;
}

$responseCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);

//close connection
curl_close($ch);

$elapsed_time = microtime(true) - $start_time;

if (200 != $httpResponse) {
if (200 != $responseCode) {
// log error
$this->handleError($ch, $httpResponse);
$this->handleError($responseCode, $responseContent);

if (($httpResponse >= 500 && $httpResponse <= 600) || 429 == $httpResponse) {
if (($responseCode >= 500 && $responseCode <= 600) || 429 == $responseCode) {
// If status code is greater than 500 and less than 600, it indicates server error
// Error code 429 indicates rate limited.
// Retry uploading in these cases.
usleep($backoff * 1000);
$backoff *= 2;
} elseif ($httpResponse >= 400) {
} elseif ($responseCode >= 400) {
break;
}
} else {
break; // no error
}
}

return $httpResponse;
}

public function executePost($ch) {
curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);

return $httpCode;
return $responseCode;
}
}