From a4cb856917b8fa00b900716af44c8b379620d84c Mon Sep 17 00:00:00 2001 From: Wolfgang Fehr <24782511+wfehr@users.noreply.github.com> Date: Fri, 9 Dec 2022 08:38:26 +0100 Subject: [PATCH] enable user configuration of curl options connecttimeout and timeout The values of these new keys are set to the defaults of curl. Now the user can also change these two values for their requirements. When server errors occur on amazons side (which can happen, as on dec 7th) you can now configure to just let the user wait for example 60s before it times out instead of 300s on each request/process. --- AmazonPay/Client.php | 4 +++- AmazonPay/HttpCurl.php | 3 +++ README.md | 2 ++ tst/unit/ClientTest.php | 4 +++- 4 files changed, 11 insertions(+), 2 deletions(-) diff --git a/AmazonPay/Client.php b/AmazonPay/Client.php index 59c1cf1..54a401c 100644 --- a/AmazonPay/Client.php +++ b/AmazonPay/Client.php @@ -51,7 +51,9 @@ class Client implements ClientInterface, LoggerAwareInterface 'client_id' => null, 'app_id' => null, 'handle_throttle' => true, - 'override_service_url' => null + 'override_service_url' => null, + 'curl_connecttimeout' => 300, + 'curl_timeout' => 0 ); private $modePath = null; diff --git a/AmazonPay/HttpCurl.php b/AmazonPay/HttpCurl.php index 0fb0fdf..9210a61 100644 --- a/AmazonPay/HttpCurl.php +++ b/AmazonPay/HttpCurl.php @@ -56,6 +56,9 @@ protected function commonCurlParams($url,$userAgent) curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $this->config['curl_connecttimeout']); + curl_setopt($ch, CURLOPT_TIMEOUT, $this->config['curl_timeout']); + if (!is_null($this->config['cabundle_file'])) { curl_setopt($ch, CURLOPT_CAINFO, $this->config['cabundle_file']); } diff --git a/README.md b/README.md index af41be7..8ba082a 100644 --- a/README.md +++ b/README.md @@ -86,6 +86,8 @@ composer require amzn/amazon-pay-sdk-php | Proxy Password | `proxy_password` | Default : `null` | | LWA Client ID | `client_id` | Default : `null` | | Handle Throttle | `handle_throttle` | Default : `true`
Other: `false` | +| Curl ConnectTimeout | `curl_connecttimeout` | Default : `300` | +| Curl Timeout | `curl_timeout` | Default : `0` | ## Setting Configuration diff --git a/tst/unit/ClientTest.php b/tst/unit/ClientTest.php index 1b117c5..a971876 100644 --- a/tst/unit/ClientTest.php +++ b/tst/unit/ClientTest.php @@ -21,7 +21,9 @@ class ClientTest extends \PHPUnit_Framework_TestCase 'proxy_host' => null, 'proxy_port' => -1, 'proxy_username' => null, - 'proxy_Password' => null + 'proxy_Password' => null, + 'curl_connecttimeout' => 300, + 'curl_timeout' => 0 ); public function testConfigArray()