Sample code for 30+ languages & platforms
PHP

Resolve a Hostname to an IP Address

See more Socket/SSL/TLS Examples

Demonstrates Socket.DnsLookup, which resolves a hostname and returns one numeric IP address.

Background. A maxWaitMs of 0 waits indefinitely; a positive value bounds the wait. Resolved results may be served from Chilkat's process-wide DNS cache.

Chilkat PHP Downloads

Chilkat2 PHP
<?php

use Chilkat2\Socket;

$socket = new Socket();

// Resolve a hostname to a numeric IP address, waiting up to 5 seconds.
try {
    $ipAddress = $socket->DnsLookup('example.com', 5000);
} catch (\Chilkat2\Exception $e) {
    echo $e->getMessage(), "\n";
    exit;
}

echo 'Resolved IP address: ', $ipAddress, "\n";