You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Use default nameservers (support /etc/resolv.conf) #29
I've tried to do something to work around this not yet available functionality, in reactphp/dns. You're idea is to read the file directly in my case i've based my resolve on the native php function.
Perhaps my code can help some others, i'm brand new to event programming, promise and other stuff so i'm sure you will see some improvement. If the LocalExecutor Fail we can fall back on the classic Executor.
I've created a LocalResolversExecutor (Query/LocalResolverExecutor.php) :
@@ -11,13 +11,14 @@ use React\Dns\Protocol\Parser;
use React\Dns\Protocol\BinaryDumper;
use React\EventLoop\LoopInterface;
use React\Dns\Query\RetryExecutor;
+use React\Dns\Query\LocalResolverExecutor;
class Factory
{
public function create($nameserver, LoopInterface $loop)
{
$nameserver = $this->addPortToServerIfMissing($nameserver);
- $executor = $this->createRetryExecutor($loop);+ $executor = $this->createLocalResolverExecutor($loop);
return new Resolver($nameserver, $executor);
}
@@ -46,7 +47,12 @@ class Factory
protected function createCachedExecutor(LoopInterface $loop, CacheInterface $cache)
{
- return new CachedExecutor($this->createRetryExecutor($loop), new RecordCache($cache));+ return new CachedExecutor($this->createLocalResolverExecutor($loop), new RecordCache($cache));+ }++ protected function createLocalResolverExecutor(LoopInterface $loop)+ {+ return new LocalResolverExecutor($loop, $this->createRetryExecutor($loop));
}
protected function addPortToServerIfMissing($nameserver)
Thanks for posting this @marty-macfly, but unfortunately your code relies on $record = gethostbyname($query->name); which makes the whole thing blocking.
This ticket likely requires us to do the following:
Find the path to the configuration (resolv.conf vs Windows?)
Find a way to load this file without blocking (filesystem component?)
Parse the contents and then instantiate as usual
Work out a proper user-facing API so you usually don't have to care about any of this
Loading the resolv.conf is implemented in #92. This file is present on most systems and will very likely cover the 90% use case (it is not present on Windows systems).
I will create a follow-up PR to implement nameserver detection for Windows. I've looked into reading this from nslookup (works, but blocks when network is not available), ipconfig /all (difficult to parse due to localization), registry (non-trivial implementation) and wmic (which I ended up using).
While this works reasonably well, I still think that consumers will have to supply their own fallback if this "autodection" fails. In my opinion, this is best left up to higher level implementation such as reactphp/socket#90.
Activity
marty-macfly commentedon Oct 4, 2016
Hello,
I've tried to do something to work around this not yet available functionality, in reactphp/dns. You're idea is to read the file directly in my case i've based my resolve on the native php function.
Perhaps my code can help some others, i'm brand new to event programming, promise and other stuff so i'm sure you will see some improvement. If the LocalExecutor Fail we can fall back on the classic Executor.
I've created a LocalResolversExecutor (Query/LocalResolverExecutor.php) :
And update Resolver/Factory.php to use it :
Regards,
Macfly
clue commentedon Oct 19, 2016
Thanks for posting this @marty-macfly, but unfortunately your code relies on
$record = gethostbyname($query->name);which makes the whole thing blocking.This ticket likely requires us to do the following:
kelunik commentedon Jan 4, 2017
I just landed here while trying to research how you guys do it on Windows. Windows stores that information in the registry unfortunately. :-(
stefanotorresi commentedon Apr 7, 2017
we could use
reactphp/child-processto launchreg querylikeamphp/windows-registrydoes.kelunik commentedon Apr 7, 2017
If you build an adapter you could just use that library instead of just recreating it.
stefanotorresi commentedon Apr 7, 2017
@kelunik good point, this is basically a use case for reactphp/promise#78
kelunik commentedon Apr 7, 2017
No, async interoperability doesn't matter for a specific case. A common event loop does.
stefanotorresi commentedon Apr 8, 2017
@kelunik I see both things as somewhat related ;)
kelunik commentedon Apr 8, 2017
They are, but a common loop makes things work, a common promise API makes things just a little bit easier.
WyriHaximus commentedon Apr 8, 2017
Aye, a common promise API/interface/spec is a first step to make that happen
clue commentedon Feb 6, 2018
Loading the
resolv.confis implemented in #92. This file is present on most systems and will very likely cover the 90% use case (it is not present on Windows systems).I will create a follow-up PR to implement nameserver detection for Windows. I've looked into reading this from
nslookup(works, but blocks when network is not available),ipconfig /all(difficult to parse due to localization), registry (non-trivial implementation) andwmic(which I ended up using).While this works reasonably well, I still think that consumers will have to supply their own fallback if this "autodection" fails. In my opinion, this is best left up to higher level implementation such as reactphp/socket#90.