From 81115a695b18082edd2cdda69a67ac9e77c6160e Mon Sep 17 00:00:00 2001 From: Kevin Gilliard Date: Tue, 10 Apr 2018 21:09:27 -0400 Subject: [PATCH 1/2] Pass valid parameter to handleError() when error occurs in libCurl --- lib/Segment/Consumer/LibCurl.php | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/lib/Segment/Consumer/LibCurl.php b/lib/Segment/Consumer/LibCurl.php index 6bded9a..59f1598 100644 --- a/lib/Segment/Consumer/LibCurl.php +++ b/lib/Segment/Consumer/LibCurl.php @@ -78,24 +78,25 @@ public function flushBatch($messages) { curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // retry failed requests just once to diminish impact on performance - $httpResponse = $this->executePost($ch); + $response = $this->executePost($ch); //close connection curl_close($ch); $elapsed_time = microtime(true) - $start_time; - if (200 != $httpResponse) { + $responseCode = $response['httpCode']; + if (200 != $responseCode) { // log error - $this->handleError($ch, $httpResponse); + $this->handleError($response['errno'], $response['errmsg']); - 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 { @@ -103,13 +104,19 @@ public function flushBatch($messages) { } } - return $httpResponse; + return $responseCode; } public function executePost($ch) { curl_exec($ch); $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); - - return $httpCode; + $errno = curl_errno($ch); + $errmsg = curl_error($ch); + + return array( + "httpCode" => $httpCode, + "errno" => $errno, + "errmsg" => $errmsg + ); } } From 3804f55d02371c9f41fbf8ba60b1a05d3bc8578a Mon Sep 17 00:00:00 2001 From: Kevin Gilliard Date: Tue, 10 Apr 2018 23:42:49 -0400 Subject: [PATCH 2/2] Fix lint errors in ./lib/Segment/Version.php --- lib/Segment/Version.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Segment/Version.php b/lib/Segment/Version.php index 5f602f8..226c0ee 100644 --- a/lib/Segment/Version.php +++ b/lib/Segment/Version.php @@ -1,4 +1,4 @@ \ No newline at end of file