Skip to content

Commit 46bb29a

Browse files
committed
[dns] README with basic and cached usage
1 parent 99a5c98 commit 46bb29a

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

README.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Dns Component
2+
3+
Async DNS resolver.
4+
5+
The main point of the DNS component is to provide async DNS resolution.
6+
However, it is really a toolkit for working with DNS messages, and could
7+
easily be used to create a DNS server.
8+
9+
## Basic usage
10+
11+
The most basic usage is to just create a resolver through the resolver
12+
factory. All you need to give it is a nameserver, then you can start resolving
13+
names, baby!
14+
15+
$loop = React\EventLoop\Factory::create();
16+
$factory = new React\Dns\Resolver\Factory();
17+
$resolver = $factory->create('8.8.8.8', $loop);
18+
19+
$resolver->resolve('igor.io', function ($ip) {
20+
echo "Host: $ip\n";
21+
});
22+
23+
But there's more.
24+
25+
## Caching
26+
27+
You can cache results by configuring the resolver to use a `CachedExecutor`:
28+
29+
$loop = React\EventLoop\Factory::create();
30+
$factory = new React\Dns\Resolver\Factory();
31+
$resolver = $factory->createCached('8.8.8.8', $loop);
32+
33+
$resolver->resolve('igor.io', function ($ip) {
34+
echo "Host: $ip\n";
35+
});
36+
37+
...
38+
39+
$resolver->resolve('igor.io', function ($ip) {
40+
echo "Host: $ip\n";
41+
});
42+
43+
If the first call returns before the second, only one query will be executed.
44+
The second result will be served from cache.

0 commit comments

Comments
 (0)