Recommend this page to a friend! |
Classes of butani kartik | PHP WebSockets Server Example | vendor/react/dns/README.md | Download |
|
DownloadDnsAsync DNS resolver for ReactPHP. The main point of the DNS component is to provide async DNS resolution. However, it is really a toolkit for working with DNS messages, and could easily be used to create a DNS server. Table of contents
Basic usageThe most basic usage is to just create a resolver through the resolver factory. All you need to give it is a nameserver, then you can start resolving names, baby!
See also the first example. The > Note that the factory loads the hosts file from the filesystem once when creating the resolver instance. Ideally, this method should thus be executed only once before the loop starts and not repeatedly while it is running. But there's more. CachingYou can cache results by configuring the resolver to use a
If the first call returns before the second, only one query will be executed. The second result will be served from an in memory cache. This is particularly useful for long running scripts where the same hostnames have to be looked up multiple times. See also the third example. Custom cache adapterBy default, the above will use an in memory cache. You can also specify a custom cache implementing
See also the wiki for possible cache implementations. ResolverInterface<a id="resolver"><!-- legacy reference --></a> resolve()The
This is one of the main methods in this package. It sends a DNS query for the given $domain name to your DNS server and returns a single IP address on success. If the DNS server sends a DNS response message that contains more than
one IP address for this query, it will randomly pick one of the IP
addresses from the response. If you want the full list of IP addresses
or want to send a different type of query, you should use the
If the DNS server sends a DNS response message that indicates an error
code, this method will reject with a If the DNS communication fails and the server does not respond with a
valid response message, this message will reject with an Pending DNS queries can be cancelled by cancelling its pending promise like so:
resolveAll()The
This is one of the main methods in this package. It sends a DNS query for the given $domain name to your DNS server and returns a list with all record values on success. If the DNS server sends a DNS response message that contains one or more
records for this query, it will return a list with all record values
from the response. You can use the If the DNS server sends a DNS response message that indicates an error
code, this method will reject with a If the DNS communication fails and the server does not respond with a
valid response message, this message will reject with an Pending DNS queries can be cancelled by cancelling its pending promise like so:
Advanced UsageUdpTransportExecutorThe This is the main class that sends a DNS query to your DNS server and is used
internally by the For more advanced usages one can utilize this class directly.
The following example looks up the
See also the fourth example. Note that this executor does not implement a timeout, so you will very likely
want to use this in combination with a
Also note that this executor uses an unreliable UDP transport and that it
does not implement any retry logic, so you will likely want to use this in
combination with a
Note that this executor is entirely async and as such allows you to execute
any number of queries concurrently. You should probably limit the number of
concurrent queries in your application or you're very likely going to face
rate limitations and bans on the resolver end. For many common applications,
you may want to avoid sending the same query multiple times when the first
one is still pending, so you will likely want to use this in combination with
a
> Internally, this class uses PHP's UDP sockets and does not take advantage of react/datagram purely for organizational reasons to avoid a cyclic dependency between the two packages. Higher-level components should take advantage of the Datagram component instead of reimplementing this socket logic from scratch. TcpTransportExecutorThe This is one of the main classes that send a DNS query to your DNS server. For more advanced usages one can utilize this class directly.
The following example looks up the
See also example #92. Note that this executor does not implement a timeout, so you will very likely
want to use this in combination with a
Unlike the Note that this executor is entirely async and as such allows you to execute
queries concurrently. The first query will establish a TCP/IP socket
connection to the DNS server which will be kept open for a short period.
Additional queries will automatically reuse this existing socket connection
to the DNS server, will pipeline multiple requests over this single
connection and will keep an idle connection open for a short period. The
initial TCP/IP connection overhead may incur a slight delay if you only send
occasional queries ? when sending a larger number of concurrent queries over
an existing connection, it becomes increasingly more efficient and avoids
creating many concurrent sockets like the UDP-based executor. You may still
want to limit the number of (concurrent) queries in your application or you
may be facing rate limitations and bans on the resolver end. For many common
applications, you may want to avoid sending the same query multiple times
when the first one is still pending, so you will likely want to use this in
combination with a
> Internally, this class uses PHP's TCP/IP sockets and does not take advantage of react/socket purely for organizational reasons to avoid a cyclic dependency between the two packages. Higher-level components should take advantage of the Socket component instead of reimplementing this socket logic from scratch. SelectiveTransportExecutorThe This class will automatically choose the correct transport protocol to send a DNS query to your DNS server. It will always try to send it over the more efficient UDP transport first. If this query yields a size related issue (truncated messages), it will retry over a streaming TCP/IP transport. For more advanced usages one can utilize this class directly.
The following example looks up the
Note that this executor only implements the logic to select the correct
transport for the given DNS query. Implementing the correct transport logic,
implementing timeouts and any retry logic is left up to the given executors,
see also Note that this executor is entirely async and as such allows you to execute
any number of queries concurrently. You should probably limit the number of
concurrent queries in your application or you're very likely going to face
rate limitations and bans on the resolver end. For many common applications,
you may want to avoid sending the same query multiple times when the first
one is still pending, so you will likely want to use this in combination with
a
HostsFileExecutorNote that the above
InstallThe recommended way to install this library is through Composer. New to Composer? This project follows SemVer. This will install the latest supported version:
See also the CHANGELOG for details about version upgrades. This project aims to run on any platform and thus does not require any PHP extensions and supports running on legacy PHP 5.3 through current PHP 8+ and HHVM. It's highly recommended to use PHP 7+ for this project. TestsTo run the test suite, you first need to clone this repo and then install all dependencies through Composer:
To run the test suite, go to the project root and run:
The test suite also contains a number of functional integration tests that rely on a stable internet connection. If you do not want to run these, they can simply be skipped like this:
LicenseMIT, see LICENSE file. References |