improve retry
This commit is contained in:
parent
8233a670bc
commit
b6b49d5430
@ -36,7 +36,6 @@ class Client
|
|||||||
|
|
||||||
protected $url;
|
protected $url;
|
||||||
protected $defaultParameters;
|
protected $defaultParameters;
|
||||||
protected $retry;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Client constructor.
|
* Client constructor.
|
||||||
@ -62,10 +61,7 @@ class Client
|
|||||||
CURLE_COULDNT_RESOLVE_HOST,
|
CURLE_COULDNT_RESOLVE_HOST,
|
||||||
CURLE_COULDNT_CONNECT,
|
CURLE_COULDNT_CONNECT,
|
||||||
CURLE_OPERATION_TIMEOUTED,
|
CURLE_OPERATION_TIMEOUTED,
|
||||||
CURLE_HTTP_POST_ERROR,
|
CURLE_SSL_CONNECT_ERROR
|
||||||
CURLE_SSL_CONNECT_ERROR,
|
|
||||||
CURLE_SEND_ERROR,
|
|
||||||
CURLE_RECV_ERROR
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -90,6 +86,7 @@ class Client
|
|||||||
array $parameters = array()
|
array $parameters = array()
|
||||||
) {
|
) {
|
||||||
$allowedMethods = array(self::METHOD_GET, self::METHOD_POST);
|
$allowedMethods = array(self::METHOD_GET, self::METHOD_POST);
|
||||||
|
$retry = 0;
|
||||||
|
|
||||||
if (!in_array($method, $allowedMethods, false)) {
|
if (!in_array($method, $allowedMethods, false)) {
|
||||||
throw new \InvalidArgumentException(
|
throw new \InvalidArgumentException(
|
||||||
@ -133,11 +130,11 @@ class Client
|
|||||||
|
|
||||||
if ($errno
|
if ($errno
|
||||||
&& in_array($errno, $this->curlErrors, false)
|
&& in_array($errno, $this->curlErrors, false)
|
||||||
&& $this->retry < 3
|
&& $retry < 3
|
||||||
) {
|
) {
|
||||||
$errno = null;
|
$errno = null;
|
||||||
$error = null;
|
$error = null;
|
||||||
++$this->retry;
|
$retry++;
|
||||||
$this->makeRequest($path, $method, $parameters);
|
$this->makeRequest($path, $method, $parameters);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -147,14 +144,4 @@ class Client
|
|||||||
|
|
||||||
return new ApiResponse($statusCode, $responseBody);
|
return new ApiResponse($statusCode, $responseBody);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Retry connect
|
|
||||||
*
|
|
||||||
* @return int
|
|
||||||
*/
|
|
||||||
public function getRetry()
|
|
||||||
{
|
|
||||||
return $this->retry;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user