mirror of
https://github.com/LBRYFoundation/lbry.com.git
synced 2025-08-23 17:47:26 +00:00
retry prefinery get requests
This commit is contained in:
parent
0b6f2d1309
commit
e5c31ee9de
2 changed files with 10 additions and 3 deletions
|
@ -36,6 +36,7 @@ class Curl
|
|||
'password' => null,
|
||||
'cookie' => null,
|
||||
'json_data' => false,
|
||||
'retry' => false,
|
||||
];
|
||||
|
||||
$invalid = array_diff_key($options, $defaults);
|
||||
|
@ -63,13 +64,14 @@ class Curl
|
|||
throw new LogicException('Unable to initialize cURL');
|
||||
}
|
||||
|
||||
$urlWithParams = $url;
|
||||
if ($method == static::GET && $params)
|
||||
{
|
||||
$url .= (strpos($url, '?') === false ? '?' : '&') . http_build_query($params);
|
||||
$urlWithParams .= (strpos($urlWithParams, '?') === false ? '?' : '&') . http_build_query($params);
|
||||
}
|
||||
|
||||
curl_setopt_array($ch, [
|
||||
CURLOPT_URL => $url,
|
||||
CURLOPT_URL => $urlWithParams,
|
||||
CURLOPT_HTTPHEADER => $options['headers'],
|
||||
CURLOPT_RETURNTRANSFER => true,
|
||||
// CURLOPT_FAILONERROR => true,
|
||||
|
@ -141,6 +143,11 @@ class Curl
|
|||
|
||||
if (curl_errno($ch))
|
||||
{
|
||||
if ($options['retry'] && is_numeric($options['retry']) && $options['retry'] > 0)
|
||||
{
|
||||
$options['retry'] -= 1;
|
||||
return static::doCurl($method, $url, $params, $options);
|
||||
}
|
||||
throw new CurlException($ch);
|
||||
}
|
||||
|
||||
|
|
|
@ -135,7 +135,7 @@ class Prefinery
|
|||
{
|
||||
$apiKey = Config::get('prefinery_key');
|
||||
return static::decodePrefineryResponse(
|
||||
Curl::get(static::DOMAIN . static::PREFIX . $endpoint . '.json?api_key=' . $apiKey, $data, static::$curlOptions)
|
||||
Curl::get(static::DOMAIN . static::PREFIX . $endpoint . '.json?api_key=' . $apiKey, $data, array_merge(static::$curlOptions, ['retry' => 3]))
|
||||
);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue