Join 4,000+ others and never miss out on new tips, tutorials, and more.
Latest version:
pecl install openswoole-22.1.2 | composer require openswoole/core:22.1.5
<?php OpenSwoole\Coroutine\System::getaddrinfo(string $domain, int $family = AF_INET, int $sockType = SOCK_STREAM, int $protocol = STREAM_IPPROTO_TCP, string $service = null, float $timeout = -1): array|false
The domain name to resolve.
The domain family to use. There are two main types: AF_INET
represents IPv4 addresses and AF_INET6
represents IPv6 addresses.
The socket type, can be: SOCK_STREAM
(default), SOCK_DGRAM
or SOCK_RAW
.
The protocol that is being used. Can be STREAM_IPPROTO_TCP
(default), STREAM_IPPROTO_UDP
, STREAM_IPPROTO_STCP
or STREAM_IPPROTO_TIPC
.
By default this is null
which means no port numbers are returned. Referrer to the manpage for getaddrinfo
to learn how to use this parameter.
A float in seconds for how long before timing out the lookup. Because a float is used, 1.5 means 1.5 seconds. By default -1
means don't time out. The lowest possible value is 0.001.
When successful it returns multiple IP addresses as an array. If there was an error then false
is returned. Use OpenSwoole\Util::getLastErrorCode()
to see what went wrong.
Get the IP addresses of a hostname.
The difference with this function is that it can return multiple IP addresses, for more information on its usage and different parameters, see the getaddrinfo manpage. There are more options compared to gethostbyname
.
You can also use OpenSwoole\Coroutine\System::dnsLookup
to get IP of a hostname.
<?php
co::run(function()
{
$ips = OpenSwoole\Coroutine\System::getaddrinfo("openswoole.com");
var_dump($ips);
});
Output:
<?php
array(2) {
[0]=>
string(12) "104.21.94.90"
[1]=>
string(14) "172.67.221.150"
}