4 * This file is part of the Monolog package.
6 * (c) Jordi Boggiano <j.boggiano@seld.be>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Monolog\Handler\Curl;
16 private static $retriableErrorCodes = array(
17 CURLE_COULDNT_RESOLVE_HOST,
18 CURLE_COULDNT_CONNECT,
21 CURLE_OPERATION_TIMEOUTED,
22 CURLE_HTTP_POST_ERROR,
23 CURLE_SSL_CONNECT_ERROR,
27 * Executes a CURL request with optional retries and exception on failure
29 * @param resource $ch curl handler
30 * @throws \RuntimeException
32 public static function execute($ch, $retries = 5, $closeAfterDone = true)
35 if (curl_exec($ch) === false) {
36 $curlErrno = curl_errno($ch);
38 if (false === in_array($curlErrno, self::$retriableErrorCodes, true) || !$retries) {
39 $curlError = curl_error($ch);
41 if ($closeAfterDone) {
45 throw new \RuntimeException(sprintf('Curl error (code %s): %s', $curlErrno, $curlError));
51 if ($closeAfterDone) {