PHPackages                             yswery/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. yswery/dns

ActiveLibrary

yswery/dns
==========

A DNS server implementation in pure PHP.

v1.4.1(6y ago)2894.0k↓100%73[2 issues](https://github.com/yswery/PHP-DNS-SERVER/issues)[2 PRs](https://github.com/yswery/PHP-DNS-SERVER/pulls)MITPHPPHP ~7.2CI failing

Since Sep 8Pushed 4y ago21 watchersCompare

[ Source](https://github.com/yswery/PHP-DNS-SERVER)[ Packagist](https://packagist.org/packages/yswery/dns)[ RSS](/packages/yswery-dns/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (4)Dependencies (14)Versions (14)Used By (0)

[![Build Status](https://camo.githubusercontent.com/5a5e21db7dad13417777399ec93396fec35534b32f9463854fcb523898c008a6/68747470733a2f2f7472617669732d63692e6f72672f7973776572792f5048502d444e532d5345525645522e737667)](https://travis-ci.org/yswery/PHP-DNS-SERVER)[![Coverage Status](https://camo.githubusercontent.com/6435e4d3d53e02d78faa8fd10ba35edc383db6c1965f88557120974777cf95f7/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f7973776572792f5048502d444e532d5345525645522f62616467652e706e67)](https://coveralls.io/github/yswery/PHP-DNS-SERVER)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/011081a722129a8b770a177aa2ee6fa90a2c336ab683e3205a39e26be14e7e5e/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f73616d75656c77696c6c69616d732f5048502d444e532d5345525645522f6261646765732f7175616c6974792d73636f72652e706e67)](https://scrutinizer-ci.com/g/samuelwilliams/PHP-DNS-SERVER/)

PHP DNS Server
==============

[](#php-dns-server)

This is an Authoritative DNS Server written in pure PHP. It will listen to DNS request on the default port (Default: port 53) and give answers about any domain that it has DNS records for. This class can be used to give DNS responses dynamically based on your pre-existing PHP code.

Requirements
------------

[](#requirements)

- `PHP 7.2+`
- Needs either `sockets` or `socket_create` PHP extension loaded (which they are by default)

Example
-------

[](#example)

Here is an example of DNS server usage:

```
require_once __DIR__.'/../vendor/autoload.php';

// JsonResolver created and provided with path to file with json dns records
$jsonResolver = new yswery\DNS\Resolver\JsonResolver([
    '/path/to/zones/example.com.json',
    '/path/to/zone/test.com.json',
]);

// System resolver acting as a fallback to the JsonResolver
$systemResolver = new yswery\DNS\Resolver\SystemResolver();

// StackableResolver will try each resolver in order and return the first match
$stackableResolver = new yswery\DNS\Resolver\StackableResolver([$jsonResolver, $systemResolver]);

// Create the eventDispatcher and add the event subscribers
$eventDispatcher = new \Symfony\Component\EventDispatcher\EventDispatcher();
$eventDispatcher->addSubscriber(new \yswery\DNS\Event\Subscriber\EchoLogger());

// Create a new instance of Server class
$server = new yswery\DNS\Server($stackableResolver, $eventDispatcher);

// Start DNS server
$server->start();
```

### Running example

[](#running-example)

- Run `composer install` to install dependencies
- Run `php example/example.php` to run the server

Query server using `dig` command to ensure proper functioning

```
$ dig @127.0.0.1 test.com A +short
111.111.111.111

$ dig @127.0.0.1 test.com TXT +short
"Some text."

$ dig @127.0.0.1 test2.com A +short
111.111.111.111
112.112.112.112
```

Zone File Storage
-----------------

[](#zone-file-storage)

PHP DNS Server supports four zone file formats out-of-the-box: Bind, JSON, XML, and YAML; each file format is supported by a specialised `Resolver` class: `BindResolver`, `JsonResolver`, `XmlResolver`, and `YamlResolver`, respectively. Example files are in the `example/` directory.

### JSON zone example

[](#json-zone-example)

```
{
  "domain": "example.com.",
  "default-ttl": 7200,
  "resource-records": [
    {
      "name": "@",
      "ttl": 10800,
      "type": "SOA",
      "class": "IN",
      "mname": "example.com.",
      "rname": "postmaster",
      "serial": 2,
      "refresh": 3600,
      "retry": 7200,
      "expire": 10800,
      "minimum": 3600
    }, {
      "type": "A",
      "address": "12.34.56.78"
    },{
      "type": "A",
      "address": "90.12.34.56"
    }, {
      "type": "AAAA",
      "address": "2001:acad:ad::32"
    }, {
      "name": "www",
      "type": "cname",
      "target": "@"
    }, {
      "name": "@",
      "type": "MX",
      "preference": 15,
      "exchange": "mail"
    }, {
      "name": "*.subdomain",
      "ttl": 3600,
      "type": "A",
      "address": "192.168.1.42"
    }
  ]
}
```

Running Tests
-------------

[](#running-tests)

Unit tests using PHPUnit are provided. A simple script is located in the root.

- run `composer install` to install PHPUnit and dependencies
- run `vendor/bin/phpunit` from the root to run the tests

Building .phar
--------------

[](#building-phar)

- run `composer run-script build-server` to build the phpdnsserver.phar file, outputs in the bin folder.
- run `composer run-script build-console` to build the phpdnscli.phar file, outputs in the bin folder.
- run `composer run-script build-installer` to build the installer. Windows support for the installer is currently limited.

Running the .phar files
-----------------------

[](#running-the-phar-files)

To run the new .phar files, download them from the release and move them to the desired folder.

- `phpdnsserver.phar` to run the phpdnsserver, uses the new filesystem by default
- `phpdnscli.phar` to run cli commands
- `phpdnsinstaller.phar` as root to create required folders and default config.

Supported command line switches
-------------------------------

[](#supported-command-line-switches)

- `--bind:b` - bind to a specific ip. Uses `0.0.0.0` by default
- `--port:p` - bind to a specific port. Uses port `53` by default
- `--config:c` - specify the config file. Uses `phpdns.json` on windows and `/etc/phpdns.json` on unix systems by default
- `--storage:s` - specify the path to the storage for zones, and logs. Uses `/etc/phpdnsserver` on unix, and current working directory on windows.

Supported Record Types
----------------------

[](#supported-record-types)

- A
- NS
- CNAME
- SOA
- PTR
- MX
- TXT
- AAAA
- AXFR
- ANY
- SRV

License
-------

[](#license)

The MIT License (MIT)

Copyright (c) 2016-2017 Yif Swery

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

###  Health Score

41

—

FairBetter than 89% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity40

Moderate usage in the ecosystem

Community29

Small or concentrated contributor base

Maturity64

Established project with proven stability

 Bus Factor1

Top contributor holds 65.1% 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.

###  Release Activity

Cadence

Every ~46 days

Recently: every ~119 days

Total

13

Last Release

2248d ago

Major Versions

v0.3 → v1.02018-10-27

PHP version history (4 changes)v0.1PHP &gt;=5.5

v0.2PHP &gt;=5.6

v1.0PHP ~7.1

v1.4PHP ~7.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/c9f3fb37b2ee0e735bd81c8198e1c20ba26c5f026a37f20dc79e3a1d37d26a0b?d=identicon)[ivanstan](/maintainers/ivanstan)

---

Top Contributors

[![samuelwilliams](https://avatars.githubusercontent.com/u/806430?v=4)](https://github.com/samuelwilliams "samuelwilliams (175 commits)")[![yswery](https://avatars.githubusercontent.com/u/6571918?v=4)](https://github.com/yswery "yswery (41 commits)")[![codenamegary](https://avatars.githubusercontent.com/u/1509951?v=4)](https://github.com/codenamegary "codenamegary (20 commits)")[![xaoseric](https://avatars.githubusercontent.com/u/643544?v=4)](https://github.com/xaoseric "xaoseric (8 commits)")[![nkakouros](https://avatars.githubusercontent.com/u/11805218?v=4)](https://github.com/nkakouros "nkakouros (7 commits)")[![raheelkhan](https://avatars.githubusercontent.com/u/7078218?v=4)](https://github.com/raheelkhan "raheelkhan (4 commits)")[![DanielRuf](https://avatars.githubusercontent.com/u/827205?v=4)](https://github.com/DanielRuf "DanielRuf (2 commits)")[![ivanstan-collab](https://avatars.githubusercontent.com/u/251970089?v=4)](https://github.com/ivanstan-collab "ivanstan-collab (2 commits)")[![kielabokkie](https://avatars.githubusercontent.com/u/1221750?v=4)](https://github.com/kielabokkie "kielabokkie (2 commits)")[![samnela](https://avatars.githubusercontent.com/u/1852108?v=4)](https://github.com/samnela "samnela (2 commits)")[![n1c](https://avatars.githubusercontent.com/u/284075?v=4)](https://github.com/n1c "n1c (1 commits)")[![ampaze](https://avatars.githubusercontent.com/u/758593?v=4)](https://github.com/ampaze "ampaze (1 commits)")[![danrwalker](https://avatars.githubusercontent.com/u/4035191?v=4)](https://github.com/danrwalker "danrwalker (1 commits)")[![gsaunders-se](https://avatars.githubusercontent.com/u/35072538?v=4)](https://github.com/gsaunders-se "gsaunders-se (1 commits)")[![abreksa4](https://avatars.githubusercontent.com/u/6120041?v=4)](https://github.com/abreksa4 "abreksa4 (1 commits)")[![webs86](https://avatars.githubusercontent.com/u/487004?v=4)](https://github.com/webs86 "webs86 (1 commits)")

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

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

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

###  Alternatives

[sylius/sylius

E-Commerce platform for PHP, based on Symfony framework.

8.4k5.6M648](/packages/sylius-sylius)[shopware/platform

The Shopware e-commerce core

3.3k1.5M3](/packages/shopware-platform)[sulu/sulu

Core framework that implements the functionality of the Sulu content management system

1.3k1.3M152](/packages/sulu-sulu)[phpro/soap-client

A general purpose SoapClient library

8885.6M46](/packages/phpro-soap-client)[drupal/core

Drupal is an open source content management platform powering millions of websites and applications.

19462.3M1.3k](/packages/drupal-core)[contao/core-bundle

Contao Open Source CMS

1231.6M2.3k](/packages/contao-core-bundle)

PHPackages © 2026

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