Skip to content

Commit

Permalink
Merge pull request #2161 from casconed/cleanup-environment-variables
Browse files Browse the repository at this point in the history
Cleanup environment variables
  • Loading branch information
sagikazarmark committed Dec 21, 2018
2 parents d9b22f4 + 00a5657 commit 330dc56
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
2 changes: 2 additions & 0 deletions docs/quickstart.rst
Expand Up @@ -609,6 +609,8 @@ behavior of the library.
Note: because the HTTP_PROXY variable may contain arbitrary user input on some (CGI) environments, the variable is only used on the CLI SAPI. See https://httpoxy.org for more information.
``HTTPS_PROXY``
Defines the proxy to use when sending requests using the "https" protocol.
``NO_PROXY``
Defines URLs for which a proxy should not be used. See :ref:`proxy-option` for usage.


Relevant ini Settings
Expand Down
10 changes: 8 additions & 2 deletions src/Handler/CurlMultiHandler.php
Expand Up @@ -37,8 +37,14 @@ public function __construct(array $options = [])
{
$this->factory = isset($options['handle_factory'])
? $options['handle_factory'] : new CurlFactory(50);
$this->selectTimeout = isset($options['select_timeout'])
? $options['select_timeout'] : 1;

if (isset($options['select_timeout'])) {
$this->selectTimeout = $options['select_timeout'];
} elseif ($selectTimeout = getenv('GUZZLE_CURL_SELECT_TIMEOUT')) {
$this->selectTimeout = $selectTimeout;
} else {
$this->selectTimeout = 1;
}
}

public function __get($name)
Expand Down
14 changes: 14 additions & 0 deletions tests/Handler/CurlMultiHandlerTest.php
Expand Up @@ -74,6 +74,20 @@ public function testDelaysConcurrently()
$this->assertGreaterThanOrEqual($expected, microtime(true));
}

public function testUsesTimeoutEnvironmentVariables()
{
$a = new CurlMultiHandler();

//default if no options are given and no environment variable is set
$this->assertEquals(1, $this->readAttribute($a, 'selectTimeout'));

putenv("GUZZLE_CURL_SELECT_TIMEOUT=3");
$a = new CurlMultiHandler();
$selectTimeout = getenv('GUZZLE_CURL_SELECT_TIMEOUT');
//Handler reads from the environment if no options are given
$this->assertEquals($selectTimeout, $this->readAttribute($a, 'selectTimeout'));
}

/**
* @expectedException \BadMethodCallException
*/
Expand Down

0 comments on commit 330dc56

Please sign in to comment.