Swoole\Coroutine\System::gethostbyname (string $host, int $family = AF_INET)

Declaration

<?php
Swoole\Coroutine\System::gethostbyname (string $host, int $family = AF_INET)

Parameters

host

Hostname to lookup

family

AF_INET for IPv4 or AF_INET6 for IPv6.

Return

ip

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

Description

Alias: Swoole\Coroutine\System::gethostbyname.

Get the IP address of a hostname.

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

Example

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