@@ -28,8 +28,12 @@ names, baby!
2828
2929``` php
3030$loop = React\EventLoop\Factory::create();
31+
32+ $config = React\Dns\Config\Config::loadSystemConfigBlocking();
33+ $server = $config->nameservers ? reset($config->nameservers) : '8.8.8.8';
34+
3135$factory = new React\Dns\Resolver\Factory();
32- $dns = $factory->create('8.8.8.8' , $loop);
36+ $dns = $factory->create($server , $loop);
3337
3438$dns->resolve('igor.io')->then(function ($ip) {
3539 echo "Host: $ip\n";
@@ -40,6 +44,14 @@ $loop->run();
4044
4145See also the [ first example] ( examples ) .
4246
47+ The ` Config ` class can be used to load the system default config. This is an
48+ operation that may access the filesystem and block. Ideally, this method should
49+ thus be executed only once before the loop starts and not repeatedly while it is
50+ running.
51+ Note that this class may return an * empty* configuration if the system config
52+ can not be loaded. As such, you'll likely want to apply a default nameserver
53+ as above if none can be found.
54+
4355> Note that the factory loads the hosts file from the filesystem once when
4456 creating the resolver instance.
4557 Ideally, this method should thus be executed only once before the loop starts
@@ -61,8 +73,12 @@ You can cache results by configuring the resolver to use a `CachedExecutor`:
6173
6274``` php
6375$loop = React\EventLoop\Factory::create();
76+
77+ $config = React\Dns\Config\Config::loadSystemConfigBlocking();
78+ $server = $config->nameservers ? reset($config->nameservers) : '8.8.8.8';
79+
6480$factory = new React\Dns\Resolver\Factory();
65- $dns = $factory->createCached('8.8.8.8' , $loop);
81+ $dns = $factory->createCached($server , $loop);
6682
6783$dns->resolve('igor.io')->then(function ($ip) {
6884 echo "Host: $ip\n";
0 commit comments