Skip to content

Commit

Permalink
Merge pull request #152 from clue-labs/dns-config
Browse files Browse the repository at this point in the history
Update DNS dependency and load system default DNS config on all supported platforms
  • Loading branch information
jsor authored Feb 27, 2018
2 parents 9db38c5 + c452f78 commit 0c8d9a6
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ install:
curl -s http://getcomposer.org/installer | php
mv composer.phar /usr/local/bin/composer
fi
- COMPOSER_ROOT_VERSION=`git describe --abbrev=0` composer install --no-interaction
- composer install --no-interaction

script:
- ./vendor/bin/phpunit --coverage-text
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -918,10 +918,12 @@ also shares all of their features and implementation details.
If you want to typehint in your higher-level protocol implementation, you SHOULD
use the generic [`ConnectorInterface`](#connectorinterface) instead.

In particular, the `Connector` class uses Google's public DNS server `8.8.8.8`
to resolve all public hostnames into underlying IP addresses by default.
If you want to use a custom DNS server (such as a local DNS relay or a company
wide DNS server), you can set up the `Connector` like this:
The `Connector` class will try to detect your system DNS settings (and uses
Google's public DNS server `8.8.8.8` as a fallback if unable to determine your
system settings) to resolve all public hostnames into underlying IP addresses by
default.
If you explicitly want to use a custom DNS server (such as a local DNS relay or
a company wide DNS server), you can set up the `Connector` like this:

```php
$connector = new Connector($loop, array(
Expand Down Expand Up @@ -1392,12 +1394,10 @@ on affected versions.
## Tests

To run the test suite, you first need to clone this repo and then install all
dependencies [through Composer](https://getcomposer.org).
Because the test suite contains some circular dependencies, you may have to
manually specify the root package version like this:
dependencies [through Composer](https://getcomposer.org):

```bash
$ COMPOSER_ROOT_VERSION=`git describe --abbrev=0` composer install
$ composer install
```

To run the test suite, go to the project root and run:
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"require": {
"php": ">=5.3.0",
"evenement/evenement": "^3.0 || ^2.0 || ^1.0",
"react/dns": "^0.4.11",
"react/dns": "^0.4.13",
"react/event-loop": "^1.0 || ^0.5 || ^0.4 || ^0.3.5",
"react/stream": "^1.0 || ^0.7.1",
"react/promise": "^2.1 || ^1.2",
Expand Down
11 changes: 10 additions & 1 deletion src/Connector.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace React\Socket;

use React\Dns\Config\Config;
use React\Dns\Resolver\Factory;
use React\Dns\Resolver\Resolver;
use React\EventLoop\LoopInterface;
Expand Down Expand Up @@ -56,9 +57,17 @@ public function __construct(LoopInterface $loop, array $options = array())
if ($options['dns'] instanceof Resolver) {
$resolver = $options['dns'];
} else {
if ($options['dns'] !== true) {
$server = $options['dns'];
} else {
// try to load nameservers from system config or default to Google's public DNS
$config = Config::loadSystemConfigBlocking();
$server = $config->nameservers ? reset($config->nameservers) : '8.8.8.8';
}

$factory = new Factory();
$resolver = $factory->create(
$options['dns'] === true ? '8.8.8.8' : $options['dns'],
$server,
$loop
);
}
Expand Down

0 comments on commit 0c8d9a6

Please sign in to comment.