PHP code example of bluelibraries / dns

1. Go to this page and download the library: Download bluelibraries/dns 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/ */

    

bluelibraries / dns example snippets


$records = DNS::getRecords('bluelibraries.com', RecordTypes::ANY);
print_r($records);

// Let's customize the DNS request handler - TCP
$dnsHandler = (new TCP())
    ->setPort(53)
    ->setNameserver('8.8.8.8')
    ->setTimeout(3) // limit execution to 3 seconds
    ->setRetries(5); // allows 5 retries if response fails

// Let's initialize the DNS records service
$dnsRecordsService = new DnsRecords($dnsHandler);

// let's get some TXT records from `bluelibraries.com`
$records = $dnsRecordsService->get('bluelibraries.com', RecordTypes::TXT);

// let's display them
print_r($records);

$dnsHandler = (new UDP())
    ->setPort(53)
    ->setNameserver('8.8.8.8')
    ->setTimeout(3) // limit execution to 3 seconds
    ->setRetries(5); // allows 5 retries if response fails

$dnsHandler = (new DIG())
    ->setPort(53)
    ->setNameserver('8.8.8.8')
    ->setTimeout(3) // limit execution to 3 seconds
    ->setRetries(5); // allows 5 retries if response fails

// DnsGetRecord allows only Timeout and Retries, but there is no control over timeout
// so the timeout may be much longer than the limit we set!
$dnsHandler = (new DnsGetRecord())
    ->setTimeout(3) // limit execution to 3 seconds
    ->setRetries(5); // allows 5 retries if response fails

$records = DNS::getRecords('bluelibraries.com', RecordTypes::TXT, DnsHandlerTypes::DNS_GET_RECORD);
print_r($records);

$records = DNS::getRecords('bluelibraries.com', RecordTypes::TXT, DnsHandlerTypes::DIG);
print_r($records);

$records = DNS::getRecords('bluelibraries.com', RecordTypes::TXT, DnsHandlerTypes::UDP);
print_r($records);

// TCP is the default DNS handler, so if you are using it then you can skip it
$records = DNS::getRecords('bluelibraries.com', RecordTypes::TXT);
print_r($records);

$records = DNS::getRecords('bluelibraries.com', RecordTypes::TXT);
print_r($records);

$records = DNS::getRecords('bluelibraries.com', RecordTypes::A);
print_r($records);

$records = DNS::getRecords('bluelibraries.com', RecordTypes::ALL, DnsHandlerTypes::DIG);
print_r($records);