-
-
Notifications
You must be signed in to change notification settings - Fork 61
Documentation and examples for advanced usage #66
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,6 +13,7 @@ easily be used to create a DNS server. | |
| * [Basic usage](#basic-usage) | ||
| * [Caching](#caching) | ||
| * [Custom cache adapter](#custom-cache-adapter) | ||
| * [Advanced usage](#advance-usage) | ||
| * [Install](#install) | ||
| * [Tests](#tests) | ||
| * [License](#license) | ||
|
|
@@ -92,6 +93,31 @@ $dns = $factory->createCached('8.8.8.8', $loop, $cache); | |
|
|
||
| See also the wiki for possible [cache implementations](https://github.com/reactphp/react/wiki/Users#cache-implementations). | ||
|
|
||
| ## Advanced Usage | ||
|
|
||
| For more advanced usages one can utilize the `Executor` directly. | ||
|
||
| The following example looks up the `IPv6` address for `igor.io`. | ||
|
|
||
| ```php | ||
| $loop = Factory::create(); | ||
|
|
||
| $executor = new Executor($loop, new Parser(), new BinaryDumper(), null); | ||
|
|
||
| $executor->query( | ||
| '8.8.8.8:53', | ||
| new Query($name, Message::TYPE_AAAA, Message::CLASS_IN, time()) | ||
| )->done(function (Message $message) { | ||
| foreach ($message->answers as $answer) { | ||
| echo 'IPv6: ' . $answer->data . PHP_EOL; | ||
| } | ||
| }, 'printf'); | ||
|
|
||
| $loop->run(); | ||
|
|
||
| ``` | ||
|
|
||
| See also the [fourth example](examples). | ||
|
|
||
| ## Install | ||
|
|
||
| The recommended way to install this library is [through Composer](http://getcomposer.org). | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| <?php | ||
|
|
||
| use React\Dns\Model\Message; | ||
| use React\Dns\Protocol\BinaryDumper; | ||
| use React\Dns\Protocol\Parser; | ||
| use React\Dns\Query\Executor; | ||
| use React\Dns\Query\Query; | ||
| use React\EventLoop\Factory; | ||
|
|
||
| require __DIR__ . '/../vendor/autoload.php'; | ||
|
|
||
| $loop = Factory::create(); | ||
|
|
||
| $executor = new Executor($loop, new Parser(), new BinaryDumper(), null); | ||
|
|
||
| $name = isset($argv[1]) ? $argv[1] : 'www.google.com'; | ||
|
|
||
| $ipv4Query = new Query($name, Message::TYPE_A, Message::CLASS_IN, time()); | ||
| $ipv6Query = new Query($name, Message::TYPE_AAAA, Message::CLASS_IN, time()); | ||
|
|
||
| $executor->query('8.8.8.8:53', $ipv4Query)->done(function (Message $message) { | ||
| foreach ($message->answers as $answer) { | ||
| echo 'IPv4: ' . $answer->data . PHP_EOL; | ||
| } | ||
| }, 'printf'); | ||
| $executor->query('8.8.8.8:53', $ipv6Query)->done(function (Message $message) { | ||
| foreach ($message->answers as $answer) { | ||
| echo 'IPv6: ' . $answer->data . PHP_EOL; | ||
| } | ||
| }, 'printf'); | ||
|
|
||
| $loop->run(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor typo here, otherwise LGTM 👍