PHPackages                             symplely/dns - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [HTTP &amp; Networking](/categories/http)
4. /
5. symplely/dns

ActiveLibrary[HTTP &amp; Networking](/categories/http)

symplely/dns
============

Async DNS Direct Query Module.

001PHP

Since Jul 17Pushed 6y agoCompare

[ Source](https://github.com/symplely/dns)[ Packagist](https://packagist.org/packages/symplely/dns)[ RSS](/packages/symplely-dns/feed)WikiDiscussions master Synced 3d ago

READMEChangelogDependenciesVersions (1)Used By (0)

dns
===

[](#dns)

[![Build Status](https://camo.githubusercontent.com/cd69317e141b58290698266b39e4014d27049e8d287775f2f62054dfa8544361/68747470733a2f2f7472617669732d63692e6f72672f73796d706c656c792f646e732e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/symplely/dns)[![codecov](https://camo.githubusercontent.com/1cff0477a244e3d7bfe88607731f87af5815c0662f724cca5e9fe1570b63333b/68747470733a2f2f636f6465636f762e696f2f67682f73796d706c656c792f646e732f6272616e63682f6d61737465722f67726170682f62616467652e737667)](https://codecov.io/gh/symplely/dns)[![Codacy Badge](https://camo.githubusercontent.com/09b1fbe4de5755084d4bc1f2d034c631f4a68f8665f8c8d17b7569bd556d5c91/68747470733a2f2f6170692e636f646163792e636f6d2f70726f6a6563742f62616467652f47726164652f3265396332646461373130373465626139386465656531663961363530383436)](https://www.codacy.com/app/techno-express/dns?utm_source=github.com&utm_medium=referral&utm_content=symplely/dns&utm_campaign=Badge_Grade)[![Maintainability](https://camo.githubusercontent.com/b839685622f37293ad3d2c52886e1a9f75b15d10e00c599053814e55915a0136/68747470733a2f2f6170692e636f6465636c696d6174652e636f6d2f76312f6261646765732f63376339353733653835633336616636383839342f6d61696e7461696e6162696c697479)](https://codeclimate.com/github/symplely/dns/maintainability)

**This package is under development, the asynchronous parts has not been implemented or added.**

This API is intended to be a half-way house offering direct to-server queries, the ability to process the response in detail but still with a simple interface for the programmer.

Usage Guide
-----------

[](#usage-guide)

### Using the Query API

[](#using-the-query-api)

You can use the DNS query API from within PHP (version 7 or later) and it requires no special raw socket permissions so should operate correctly in most environments.

To use the API you must create a Query object (with a DNS server hostname/IP and other optional parameters), perform a query (either a full query where you specify the type of result or a smart A lookup &lt;#SmartALookup&gt;) and deal with the answer.

The answer will either be false if an error occured (see the code below for an example error trap) or a Answer object containing a "count" property (the number of records returned as answers) and an array of Result objects containing each answer given to the query.

The following is an example script to perform an A record (IP address) lookup

```
// A simple DNS query example
require("vendor/autoload.php"); // Require API Source

use Async\Dns\Query;

// Your DNS Server
$dns_server = "ns.somehost.com";

// create Query object - there are other options we could pass here
$dns_query = new Query($dns_server);

// the question we will ask
$question = "www.somehost.com";

// the type of response(s) we want for this question
$type = "A";

// do the query
$result = $dns_query->query($question, $type);

// Trap Errors
if ($dns_query->->hasError()) {
    // error occurred
    echo $dns_query->getLastError();
    exit();
}

//Process Results
$count = $result->count(); // number of results returned
foreach ($result as $result_count) {
    // only after A records
    if ($result_count->getTypeId() == "A") {
        echo $question." has IP address ".$result_count->getData()."";
        echo $result_count->getString()."";
    }
}
```

Which if all goes well should output something like...

- [www.somehost.com](http://www.somehost.com) has IP address 10.2.3.4
- [www.somehost.com](http://www.somehost.com) has address 10.2.3.4

The first output is from our script writing the question and the "data" result, the second when we output the "string" property of the answer which is the specific record in human-readable form (if the type is known).

> **A Note of Warning and Why Check the Answer Type Above**

DNS is not an entirely straightforward protocol and things which on the surface may seem simple may not be when you delve deeper (if you already understand DNS then skip ahead).

For example an IP lookup (A record lookup) for a host on a specific DNS server may well not just return a single answer record containing the IP address. The host may be multi-honed and return multiple records any which may not be an IP address but a CNAME alias. The nameserver you are querying may not do a recursive or cache lookup for you and so return no answers even though the domain and host do exist.

For this reason we must actually process the results (unless of course we just want to see what data is provided for a query and not actually do anything with that answer).

Hosts with just a CNAME alias will not be resolved to an IP address in the answer section. If we ask for the A record of [www.somehost.com](http://www.somehost.com) we may just get back a CNAME of webhost.somehost.com. To turn this into an IP address we must then either hope it was provided in the additional answer section (and check - see below for details) or perform another A record lookup on webhost.somehost.com.

If you just want an IP address for a host then either PHP's inbuilt gethostbyname()  or this API's SmartALookup() &lt;#SmartALookup&gt; are probably what you're after rather than a full blown query.

### Answer and Query Types

[](#answer-and-query-types)

Record (query and result) types the API supports will should return sensible data for are: A, NS, PTR, MX, CNAME, TXT and SOA.

Asking for an unsupported type will cause the query to fail. Unsupported types which are returned as result records will have null "string" and "typeid" properties but will contain the binary data in "data" and the decimal record type in "type".

### Answer Results

[](#answer-results)

If a query succeeds it returns a Answer object containing a counter property "count" indicating the number of answer records returned and an array of Result objects containing each of these records in turn.

The Answer object breaks down as follows: $answer-&gt;count Number of answer records contained $answer-&gt;results\[x\]-&gt;typeid Textual record type ID (A, MX, CNAME etc) $answer-&gt;results\[x\]-&gt;type Numeric record type (decimal) $answer-&gt;results\[x\]-&gt;class Numeric class type (decimal) $answer-&gt;results\[x\]-&gt;data Data returned (i.e. IP address or hostname) $answer-&gt;results\[x\]-&gt;domain Domain name data is for $answer-&gt;results\[x\]-&gt;string String representation of the answer (i.e. [www.fish.sea](http://www.fish.sea) has address x.y.z) $answer-&gt;results\[x\]-&gt;extras Type-specific array of extra fields (i.e. "level" for MX exchanges) - see below

### Type-specific Extras

[](#type-specific-extras)

Some result types have extended extra information which will be in array form in the "extras" property of a Result object.

MX record types have the decimal mail exchange priority in extas\['level'\]

SOA record types have the responsible contact for the domain in extras\['responsible'\] as well as the following: extras\['serial'\] - domain serial extras\['refresh'\] - domain refresh extras\['retry'\] - domain retry extras\['expiry'\] - domain expiry extras\['minttl'\] - domain mimumum time-to-live (ttl)

### Smart A Lookup

[](#smart-a-lookup)

Because doing an A lookup won't always return an IP address and sometimes you're just after an IP address (not potentially a list of them and aliases etc) the Query class provides the SmartALookup() method.

This function simply takes a hostname and returns an IP address or a null string if lookup failed (you can then check the Query lasterror property to see if the query actually failed or just returned no results).

If the result data contains an IP address it will be returned (first preference). If no IP addresses were provided but an alias CNAME is given then this will be looked up (recursing up to a depth of five aliases).

In effect this is a nameserver-specific version of gethostbyname() but returns a null string rather than the unmodified IP on failure.

More Information
----------------

[](#more-information)

The technical documentation can be found [here](https://github.com/symplely/dns/blob/master/DNSQueryAPITechnicalDocs.md)

###  Health Score

18

—

LowBetter than 8% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity1

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity36

Early-stage or recently created project

 Bus Factor1

Top contributor holds 52.3% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/b1a9d88c23f07f785e0358746ae2384950a6f8dac0c3bd4fbbc910e94f7eb637?d=identicon)[techno-express](/maintainers/techno-express)

---

Top Contributors

[![TheTechsTech](https://avatars.githubusercontent.com/u/29784725?v=4)](https://github.com/TheTechsTech "TheTechsTech (34 commits)")[![purplepixie](https://avatars.githubusercontent.com/u/1479871?v=4)](https://github.com/purplepixie "purplepixie (21 commits)")[![bjdelange](https://avatars.githubusercontent.com/u/2757512?v=4)](https://github.com/bjdelange "bjdelange (6 commits)")[![Derekholio](https://avatars.githubusercontent.com/u/6242524?v=4)](https://github.com/Derekholio "Derekholio (2 commits)")[![xatr0z](https://avatars.githubusercontent.com/u/1092510?v=4)](https://github.com/xatr0z "xatr0z (1 commits)")[![Yurij](https://avatars.githubusercontent.com/u/11015706?v=4)](https://github.com/Yurij "Yurij (1 commits)")

---

Tags

asyncasynchronouscoroutinednsphpyield

### Embed Badge

![Health badge](/badges/symplely-dns/health.svg)

```
[![Health](https://phpackages.com/badges/symplely-dns/health.svg)](https://phpackages.com/packages/symplely-dns)
```

###  Alternatives

[friendsofsymfony/rest-bundle

This Bundle provides various tools to rapidly develop RESTful API's with Symfony

2.8k73.3M319](/packages/friendsofsymfony-rest-bundle)[php-http/discovery

Finds and installs PSR-7, PSR-17, PSR-18 and HTTPlug implementations

1.3k309.5M1.2k](/packages/php-http-discovery)[nyholm/psr7

A fast PHP7 implementation of PSR-7

1.3k235.4M2.4k](/packages/nyholm-psr7)[pusher/pusher-php-server

Library for interacting with the Pusher REST API

1.5k94.8M293](/packages/pusher-pusher-php-server)[spatie/crawler

Crawl all internal links found on a website

2.8k16.3M52](/packages/spatie-crawler)[react/http

Event-driven, streaming HTTP client and server implementation for ReactPHP

78126.4M414](/packages/react-http)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
