From 37068c4a2ded769affbcab234e3ede67b1d24388 Mon Sep 17 00:00:00 2001 From: Andy Thompson Date: Fri, 16 Oct 2015 11:03:13 +0100 Subject: [PATCH 1/2] Add the ability to define SoapClient timeout in Curl implementation Also default it to the timeout \SoapClient uses --- src/BeSimple/SoapClient/Curl.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/BeSimple/SoapClient/Curl.php b/src/BeSimple/SoapClient/Curl.php index e777fc8f..6be295e0 100644 --- a/src/BeSimple/SoapClient/Curl.php +++ b/src/BeSimple/SoapClient/Curl.php @@ -59,6 +59,9 @@ public function __construct(array $options = array(), $followLocationMaxRedirect if (!isset($options['user_agent'])) { $options['user_agent'] = self::USER_AGENT; } + if (!isset($options['timeout']) { + $options['timeout'] = ini_get('default_socket_timeout'); + } $this->followLocationMaxRedirects = $followLocationMaxRedirects; // make http request @@ -72,6 +75,7 @@ public function __construct(array $options = array(), $followLocationMaxRedirect CURLOPT_HEADER => true, CURLOPT_USERAGENT => $options['user_agent'], CURLINFO_HEADER_OUT => true, + CURLOPT_TIMEOUT => $options['timeout'], ); curl_setopt_array($this->ch, $curlOptions); if (isset($options['compression']) && !($options['compression'] & SOAP_COMPRESSION_ACCEPT)) { From 05cd68e72fde5797572a56a23f60091c5d776ce0 Mon Sep 17 00:00:00 2001 From: Andy Thompson Date: Fri, 16 Oct 2015 11:09:55 +0100 Subject: [PATCH 2/2] Don't set timeout if it's null or 0 --- src/BeSimple/SoapClient/Curl.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/BeSimple/SoapClient/Curl.php b/src/BeSimple/SoapClient/Curl.php index 6be295e0..eb86a365 100644 --- a/src/BeSimple/SoapClient/Curl.php +++ b/src/BeSimple/SoapClient/Curl.php @@ -75,7 +75,6 @@ public function __construct(array $options = array(), $followLocationMaxRedirect CURLOPT_HEADER => true, CURLOPT_USERAGENT => $options['user_agent'], CURLINFO_HEADER_OUT => true, - CURLOPT_TIMEOUT => $options['timeout'], ); curl_setopt_array($this->ch, $curlOptions); if (isset($options['compression']) && !($options['compression'] & SOAP_COMPRESSION_ACCEPT)) { @@ -84,6 +83,9 @@ public function __construct(array $options = array(), $followLocationMaxRedirect if (isset($options['connection_timeout'])) { curl_setopt($this->ch, CURLOPT_CONNECTTIMEOUT, $options['connection_timeout']); } + if (!empty($options['timeout'])) { + curl_setopt($this->ch, CURLOPT_TIMEOUT, $options['timeout']); + } if (isset($options['proxy_host'])) { if (false !== $options['proxy_host']) {