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

ActiveLibrary

badcow/dns
==========

A PHP library for creating DNS zone files based on RFC1035

v4.3.0(1y ago)264203.8k—9.1%42[6 issues](https://github.com/Badcow/DNS/issues)[4 PRs](https://github.com/Badcow/DNS/pulls)11MITPHPPHP ^8.0CI passing

Since Aug 17Pushed 1y ago12 watchersCompare

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

READMEChangelog (10)Dependencies (5)Versions (55)Used By (11)

Badcow DNS Library
==================

[](#badcow-dns-library)

The aim of this project is to create abstract object representations of DNS records in PHP. The project consists of various classes representing DNS objects (such as `Zone`, `ResourceRecord`, and various `RData` types), a parser to convert BIND style text files to the PHP objects, and builders to create aesthetically pleasing BIND records.

The library can parse and encode DNS messages enabling developers to create DNS client/server platforms in pure PHP.

Build Status
------------

[](#build-status)

[![Build Status: PHP 8](https://github.com/Badcow/DNS/workflows/PHP%208/badge.svg)](https://github.com/Badcow/DNS/actions?query=workflow%3A%22PHP+8%22)

Contents
--------

[](#contents)

1. [Example usage](#example-usage)
2. [Example Output](#output)
3. [Supported Types](#supported-types)
4. [Parsing BIND Records](#parsing-bind-records)

Example usage
-------------

[](#example-usage)

```
require_once '/path/to/vendor/autoload.php';

use Badcow\DNS\Classes;
use Badcow\DNS\Zone;
use Badcow\DNS\Rdata\Factory;
use Badcow\DNS\ResourceRecord;
use Badcow\DNS\AlignedBuilder;

$zone = new Zone('example.com.');
$zone->setDefaultTtl(3600);

$soa = new ResourceRecord;
$soa->setName('@');
$soa->setClass(Classes::INTERNET);
$soa->setRdata(Factory::Soa(
    'example.com.',
    'post.example.com.',
    '2014110501',
    3600,
    14400,
    604800,
    3600
));

$ns1 = new ResourceRecord;
$ns1->setName('@');
$ns1->setClass(Classes::INTERNET);
$ns1->setRdata(Factory::Ns('ns1.nameserver.com.'));

$ns2 = new ResourceRecord;
$ns2->setName('@');
$ns2->setClass(Classes::INTERNET);
$ns2->setRdata(Factory::Ns('ns2.nameserver.com.'));

$a = new ResourceRecord;
$a->setName('sub.domain');
$a->setRdata(Factory::A('192.168.1.42'));
$a->setComment('This is a local ip.');

$a6 = new ResourceRecord;
$a6->setName('ipv6.domain');
$a6->setRdata(Factory::Aaaa('::1'));
$a6->setComment('This is an IPv6 domain.');

$mx1 = new ResourceRecord;
$mx1->setName('@');
$mx1->setRdata(Factory::Mx(10, 'mail-gw1.example.net.'));

$mx2 = new ResourceRecord;
$mx2->setName('@');
$mx2->setRdata(Factory::Mx(20, 'mail-gw2.example.net.'));

$mx3 = new ResourceRecord;
$mx3->setName('@');
$mx3->setRdata(Factory::Mx(30, 'mail-gw3.example.net.'));

$zone->addResourceRecord($soa);
$zone->addResourceRecord($mx2);
$zone->addResourceRecord($ns1);
$zone->addResourceRecord($mx3);
$zone->addResourceRecord($a);
$zone->addResourceRecord($a6);
$zone->addResourceRecord($ns2);
$zone->addResourceRecord($mx1);

$builder = new AlignedBuilder();
echo $builder->build($zone);
```

### Output

[](#output)

```
$ORIGIN example.com.
$TTL 3600
@            IN SOA  (
                     example.com.      ; MNAME
                     post.example.com. ; RNAME
                     2014110501        ; SERIAL
                     3600              ; REFRESH
                     14400             ; RETRY
                     604800            ; EXPIRE
                     3600              ; MINIMUM
                     )

; NS RECORDS
@            IN NS   ns1.nameserver.com.
@            IN NS   ns2.nameserver.com.

; A RECORDS
sub.domain      A    192.168.1.42; This is a local ip.

; AAAA RECORDS
ipv6.domain     AAAA ::1; This is an IPv6 domain.

; MX RECORDS
@               MX   10 mail-gw1.example.net.
@               MX   20 mail-gw2.example.net.
@               MX   30 mail-gw3.example.net.
```

The above is an example of the `AlignedBuilder` which creates records that are much more aesthetically pleasing. You can also use the flat `ZoneBuilder`, the output of which is below:

```
...
echo ZoneBuilder::build($zone);
```

```
$ORIGIN example.com.
$TTL 3600
@ IN SOA example.com. post.example.com. 2014110501 3600 14400 604800 3600
@ MX 20 mail-gw2.example.net.
@ IN NS ns1.nameserver.com.
@ MX 30 mail-gw3.example.net.
sub.domain A 192.168.1.42; This is a local ip.
ipv6.domain AAAA ::1; This is an IPv6 domain.
@ IN NS ns2.nameserver.com.
@ MX 10 mail-gw1.example.net.
```

Supported Types
---------------

[](#supported-types)

All ubiquitous DNS types are supported. For full details on supported types see [the Documentation](docs/Supported-Types.md).

Parsing BIND Records
--------------------

[](#parsing-bind-records)

BIND Records can be parsed into PHP objects using `Badcow\DNS\Parser\Parser`

```
$file = file_get_contents('/path/to/example.com.txt');
$zone = Badcow\DNS\Parser\Parser::parse('example.com.', $file); //Badcow Zone Object
```

Simple as that.

More examples can be found in the [The Docs](docs/Parser)

###  Health Score

56

—

FairBetter than 98% of packages

Maintenance40

Moderate activity, may be stable

Popularity53

Moderate usage in the ecosystem

Community34

Small or concentrated contributor base

Maturity82

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 93.8% 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 ~71 days

Recently: every ~323 days

Total

52

Last Release

650d ago

Major Versions

v0.19 → v1.02018-09-02

v1.3 → v2.02018-12-15

v2.4.0 → v3.02019-11-30

v3.5.0 → v4.0.02020-12-01

PHP version history (7 changes)v0.1PHP &gt;=5.4

v0.16PHP &gt;=5.5

v1.0PHP ~7.1

v3.0PHP ~7.2

v4.0.0PHP ^7.3

v4.1.0PHP ^7.3 || ^8.0

v4.2.x-devPHP ^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/5dd5f6a3443d2ee5f0121397886a0141ba4f462d1a9686ba613de2815726b62f?d=identicon)[samuelwilliams](/maintainers/samuelwilliams)

---

Top Contributors

[![samuelwilliams](https://avatars.githubusercontent.com/u/806430?v=4)](https://github.com/samuelwilliams "samuelwilliams (457 commits)")[![Livda](https://avatars.githubusercontent.com/u/9930567?v=4)](https://github.com/Livda "Livda (9 commits)")[![yeganemehr](https://avatars.githubusercontent.com/u/16887332?v=4)](https://github.com/yeganemehr "yeganemehr (6 commits)")[![srsbiz](https://avatars.githubusercontent.com/u/1525842?v=4)](https://github.com/srsbiz "srsbiz (4 commits)")[![scrutinizer-auto-fixer](https://avatars.githubusercontent.com/u/6253494?v=4)](https://github.com/scrutinizer-auto-fixer "scrutinizer-auto-fixer (3 commits)")[![necrogami](https://avatars.githubusercontent.com/u/33020?v=4)](https://github.com/necrogami "necrogami (2 commits)")[![a3dho3yn](https://avatars.githubusercontent.com/u/5849028?v=4)](https://github.com/a3dho3yn "a3dho3yn (1 commits)")[![SilvanWakker](https://avatars.githubusercontent.com/u/16898091?v=4)](https://github.com/SilvanWakker "SilvanWakker (1 commits)")[![SloEddy](https://avatars.githubusercontent.com/u/1764938?v=4)](https://github.com/SloEddy "SloEddy (1 commits)")[![fbett](https://avatars.githubusercontent.com/u/24937658?v=4)](https://github.com/fbett "fbett (1 commits)")[![tomschlick](https://avatars.githubusercontent.com/u/70184?v=4)](https://github.com/tomschlick "tomschlick (1 commits)")[![adamnicholson](https://avatars.githubusercontent.com/u/7761178?v=4)](https://github.com/adamnicholson "adamnicholson (1 commits)")

---

Tags

binddnsnamedphpweb

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[getkirby/cms

The Kirby core

1.5k535.5k352](/packages/getkirby-cms)[typo3/cms

TYPO3 CMS is a free open source Content Management Framework initially created by Kasper Skaarhoj and licensed under GNU/GPL.

1.2k1.9M122](/packages/typo3-cms)[jason-munro/cypht

Lightweight Open Source webmail written in PHP and JavaScript

1.5k146.0k](/packages/jason-munro-cypht)[typo3/cms-core

TYPO3 CMS Core

3512.3M3.8k](/packages/typo3-cms-core)[dolondro/google-authenticator

Code to authenticate against the Google Authenticator app

113466.1k](/packages/dolondro-google-authenticator)[soneso/stellar-php-sdk

Stellar PHP SDK for the Stellar Network

4048.2k4](/packages/soneso-stellar-php-sdk)

PHPackages © 2026

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