1. Go to this page and download the library: Download tourze/workerman-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/ */
tourze / workerman-dns-client example snippets
use React\Dns\Model\Message;
use Symfony\Component\Cache\Adapter\ArrayAdapter;
use Tourze\Workerman\DnsClient\DnsQueryFactory;
// Create a cache adapter
$cache = new ArrayAdapter();
// Create a DNS query client
$dnsClient = DnsQueryFactory::create($cache, 'example.com', Message::TYPE_A);
// Perform DNS query
$dnsClient->resolveIP(
function (string $ip) {
echo "Resolution successful: $ip\n";
},
function () {
echo "Resolution failed\n";
}
);
use React\Dns\Model\Message;
use Symfony\Component\Cache\Adapter\ArrayAdapter;
use Tourze\Workerman\DnsClient\DnsQueryFactory;
$cache = new ArrayAdapter();
$dnsClient = DnsQueryFactory::create(
$cache, // Cache adapter
'example.com', // Domain to query
Message::TYPE_A, // Query type (A, AAAA, MX, etc.)
'8.8.8.8', // DNS server address (default: 1.1.1.1)
53, // DNS server port (default: 53)
10 // Query timeout in seconds (default: 5)
);
$dnsClient->resolveIP(
function (string $ip) {
echo "Resolution successful: $ip\n";
},
function () {
echo "Resolution failed\n";
}
);
use Tourze\Workerman\DnsClient\Cache\DnsCacheInterface;
use Tourze\Workerman\DnsClient\Connection\UdpConnectionFactoryInterface;
use Tourze\Workerman\DnsClient\DnsConfig;
use Tourze\Workerman\DnsClient\DnsQuery;
use Tourze\Workerman\DnsClient\Logger\LoggerInterface;
use Tourze\Workerman\DnsClient\Protocol\DnsProtocolHandlerInterface;
use Tourze\Workerman\DnsClient\Timer\TimerInterface;
// Custom configuration
$config = new DnsConfig('example.com', Message::TYPE_A, '8.8.8.8', 53, 10);
// Inject custom components
$dnsQuery = new DnsQuery(
$config, // Configuration
$customCache, // Your cache implementation
$customConnectionFactory, // Your connection factory
$customProtocolHandler, // Your protocol handler
$customTimer, // Your timer implementation
$customLogger // Your logger implementation
);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.