Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup environment variables #2161

Merged
merged 2 commits into from Dec 21, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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