ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
Util.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the Monolog package.
5  *
6  * (c) Jordi Boggiano <j.boggiano@seld.be>
7  *
8  * For the full copyright and license information, please view the LICENSE
9  * file that was distributed with this source code.
10  */
11 
13 
14 class Util
15 {
16  private static $retriableErrorCodes = array(
17  CURLE_COULDNT_RESOLVE_HOST,
18  CURLE_COULDNT_CONNECT,
19  CURLE_HTTP_NOT_FOUND,
20  CURLE_READ_ERROR,
21  CURLE_OPERATION_TIMEOUTED,
22  CURLE_HTTP_POST_ERROR,
23  CURLE_SSL_CONNECT_ERROR,
24  );
25 
32  public static function execute($ch, $retries = 5, $closeAfterDone = true)
33  {
34  while ($retries--) {
35  if (curl_exec($ch) === false) {
36  $curlErrno = curl_errno($ch);
37 
38  if (false === in_array($curlErrno, self::$retriableErrorCodes, true) || !$retries) {
39  $curlError = curl_error($ch);
40 
41  if ($closeAfterDone) {
42  curl_close($ch);
43  }
44 
45  throw new \RuntimeException(sprintf('Curl error (code %s): %s', $curlErrno, $curlError));
46  }
47 
48  continue;
49  }
50 
51  if ($closeAfterDone) {
52  curl_close($ch);
53  }
54  break;
55  }
56  }
57 }
static execute($ch, $retries=5, $closeAfterDone=true)
Executes a CURL request with optional retries and exception on failure.
Definition: Util.php:32
Create styles array
The data for the language used.
static $retriableErrorCodes
Definition: Util.php:16