Commit 0178d323 authored by Yevgen Kovalienia's avatar Yevgen Kovalienia

CURL and PECL_HTTP adapters set connection timeout and dns cache timeout...

CURL and PECL_HTTP adapters set connection timeout and dns cache timeout (which is equal to "timeout" option value)
parent 27d51fe4
...@@ -149,6 +149,7 @@ class Curl extends Configurable implements AdapterInterface ...@@ -149,6 +149,7 @@ class Curl extends Configurable implements AdapterInterface
curl_setopt($handler, CURLOPT_FOLLOWLOCATION, true); curl_setopt($handler, CURLOPT_FOLLOWLOCATION, true);
} }
curl_setopt($handler, CURLOPT_TIMEOUT, $options['timeout']); curl_setopt($handler, CURLOPT_TIMEOUT, $options['timeout']);
curl_setopt($handler, CURLOPT_CONNECTTIMEOUT, $options['timeout']);
if ($proxy = $this->getOption('proxy')) { if ($proxy = $this->getOption('proxy')) {
curl_setopt($handler, CURLOPT_PROXY, $proxy); curl_setopt($handler, CURLOPT_PROXY, $proxy);
......
...@@ -132,6 +132,9 @@ class PeclHttp extends Configurable implements AdapterInterface ...@@ -132,6 +132,9 @@ class PeclHttp extends Configurable implements AdapterInterface
* {@link http://us.php.net/manual/en/http.constants.php * {@link http://us.php.net/manual/en/http.constants.php
* HTTP Predefined Constant} * HTTP Predefined Constant}
* *
* {@link http://us.php.net/manual/en/http.request.options.php
* HttpRequest options}
*
* @throws InvalidArgumentException * @throws InvalidArgumentException
* @param Request $request * @param Request $request
* @param Endpoint $endpoint * @param Endpoint $endpoint
...@@ -190,7 +193,13 @@ class PeclHttp extends Configurable implements AdapterInterface ...@@ -190,7 +193,13 @@ class PeclHttp extends Configurable implements AdapterInterface
} }
$httpRequest->setMethod($method); $httpRequest->setMethod($method);
$httpRequest->setOptions(array('timeout' => $endpoint->getTimeout())); $httpRequest->setOptions(
array(
'timeout' => $endpoint->getTimeout(),
'connecttimeout' => $endpoint->getTimeout(),
'dns_cache_timeout' => $endpoint->getTimeout(),
)
);
$httpRequest->setHeaders($headers); $httpRequest->setHeaders($headers);
return $httpRequest; return $httpRequest;
......
...@@ -129,6 +129,8 @@ class PeclHttpTest extends \PHPUnit_Framework_TestCase ...@@ -129,6 +129,8 @@ class PeclHttpTest extends \PHPUnit_Framework_TestCase
$this->assertEquals( $this->assertEquals(
array( array(
'timeout' => 10, 'timeout' => 10,
'connecttimeout' => 10,
'dns_cache_timeout' => 10,
'headers' => array( 'headers' => array(
'Content-Type' => 'application/json', 'Content-Type' => 'application/json',
'User-Agent' => 'Foo', 'User-Agent' => 'Foo',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment