Swoole\Coroutine\System::dnsLookup (string $host)

Declaration

<?php
Swoole\Coroutine\System::dnsLookup (string $host, float $timeout)

Parameters

host

Hostname to lookup

timeout

Timeout of the DNS lookup

Return

ip

if success, it returns the IP address, otherwise it returns FALSE.

Description

Alias: Swoole\Coroutine::dnsLookup.

Get the IP address of a hostname.

You can also use Swoole\Coroutine::gethostbyname to get IP of a hostname.

DNS lookup is using the DNS in /etc/resolve.conf.

Only IPv4 is supported.

The error details can accessed by using swoole_last_error().

Example

<?php
Co::set(['dns_server' => '192.0.0.1:53']);
Co\run(function () {
    $ip = Swoole\Coroutine\System::dnsLookup('www.google.com', 0.5);
});