From f258a2ed2970a60100a0cce8b7ea5df6df9b08b9 Mon Sep 17 00:00:00 2001 From: psquickitjayant Date: Tue, 7 Jul 2015 21:55:03 +0530 Subject: [PATCH 1/2] Added support for retry logic --- src/Monolog/Handler/LogglyHandler.php | 68 ++++++++++++++++++++------- 1 file changed, 51 insertions(+), 17 deletions(-) diff --git a/src/Monolog/Handler/LogglyHandler.php b/src/Monolog/Handler/LogglyHandler.php index 9785cec0..ecb0a4d3 100644 --- a/src/Monolog/Handler/LogglyHandler.php +++ b/src/Monolog/Handler/LogglyHandler.php @@ -1,13 +1,13 @@ - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ +* This file is part of the Monolog package. +* +* (c) Jordi Boggiano +* +* For the full copyright and license information, please view the LICENSE +* file that was distributed with this source code. +*/ namespace Monolog\Handler; @@ -15,12 +15,12 @@ use Monolog\Logger; use Monolog\Formatter\LogglyFormatter; /** - * Sends errors to Loggly. - * - * @author Przemek Sobstel - * @author Adam Pancutt - * @author Gregory Barchard - */ +* Sends errors to Loggly. +* +* @author Przemek Sobstel +* @author Adam Pancutt +* @author Gregory Barchard +*/ class LogglyHandler extends AbstractProcessingHandler { const HOST = 'logs-01.loggly.com'; @@ -92,11 +92,45 @@ class LogglyHandler extends AbstractProcessingHandler curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); - if (curl_exec($ch) === false) { - throw new \RuntimeException(sprintf('Curl error (code %s): %s', curl_errno($ch), curl_error($ch))); - } + $RETRY_COUNT = 5; + $TOTAL_RETRIES = 0; - curl_close($ch); + /* + * Curl error code 6 : CURLE_COULDNT_RESOLVE_HOST + * Curl error code 7 : CURLE_COULDNT_CONNECT + * Curl error code 9 : CURLE_REMOTE_ACCESS_DENIED + * Curl error code 22 : CURLE_HTTP_RETURNED_ERROR + * Curl error code 25 : CURLE_UPLOAD_FAILED + * Curl error code 26 : CURLE_READ_ERROR + * Curl error code 28 : CURLE_OPERATION_TIMEDOUT + * Curl error code 34 : CURLE_HTTP_POST_ERROR + * Curl error code 35 : CURLE_SSL_CONNECT_ERROR + * + * Curl Error Codes : http://curl.haxx.se/libcurl/c/libcurl-errors.html + */ + $CurlErrorCodesForRetries = array(6,7,9,22,25,26,28,34,35); + + do + { + $TOTAL_RETRIES = $TOTAL_RETRIES + 1; + if (curl_exec($ch) === false) { + /* + If the error cannot be controlled by retries or + total retry count is already completed then + show error and break the loop + */ + if(in_array(curl_errno($ch),$CurlErrorCodesForRetries) === false + || $TOTAL_RETRIES > $RETRY_COUNT){ + echo sprintf('Curl error (code %s): %s', curl_errno($ch), curl_error($ch)); + curl_close($ch); + break; + } + } + else{ + curl_close($ch); + break; + } + }while($TOTAL_RETRIES <= $RETRY_COUNT); } protected function getDefaultFormatter() From f17e5a6ec320adafadc879549870977068e7fa4a Mon Sep 17 00:00:00 2001 From: psquickitjayant Date: Wed, 8 Jul 2015 02:35:47 +0530 Subject: [PATCH 2/2] Fixed formatting issues --- src/Monolog/Handler/LogglyHandler.php | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/Monolog/Handler/LogglyHandler.php b/src/Monolog/Handler/LogglyHandler.php index ecb0a4d3..c59c21bd 100644 --- a/src/Monolog/Handler/LogglyHandler.php +++ b/src/Monolog/Handler/LogglyHandler.php @@ -1,13 +1,13 @@ -* -* For the full copyright and license information, please view the LICENSE -* file that was distributed with this source code. -*/ + * This file is part of the Monolog package. + * + * (c) Jordi Boggiano + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Monolog\Handler; @@ -15,12 +15,12 @@ use Monolog\Logger; use Monolog\Formatter\LogglyFormatter; /** -* Sends errors to Loggly. -* -* @author Przemek Sobstel -* @author Adam Pancutt -* @author Gregory Barchard -*/ + * Sends errors to Loggly. + * + * @author Przemek Sobstel + * @author Adam Pancutt + * @author Gregory Barchard + */ class LogglyHandler extends AbstractProcessingHandler { const HOST = 'logs-01.loggly.com';