PHP code example of arrayaccess / dns-client

1. Go to this page and download the library: Download arrayaccess/dns-client library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

arrayaccess / dns-client example snippets


use ArrayAccess\DnsRecord\Cache\Adapter\Psr6CacheAdapter;
use ArrayAccess\DnsRecord\DnsServerStorage;
use ArrayAccess\DnsRecord\Resolver;

$cache = new Psr6CacheAdapter();
// $cache->setCacheItemPool($cacheProvider);
$dnsServer = DnsServerStorage::createDefault();
$resolver = new Resolver($dnsServer, $cache);

/**
 * Lookup Single 
 */
$useCache = true; // default to true
$timeout = 3.5; // 3.5 seconds
$response = $resolver->lookup('domain-name.ext', 'A', 'IN', $timeout, $useCache);

/**
 * Enable Pseudo OPT 
 */
$resolver->setDnsSec(true);
$response = $resolver->lookup('domain-name.ext', 'A', 'IN');
$answers = $response->getAnswers();
$records = $answers->getRecords();
// Filter "A" Address Only
$arrayA = $records->getFilteredType('A');