Jesus · Bible · HTML · CSS · JS · PHP · SVG · Applications

socket_addrinfo_lookup

Description

The socket_addrinfo_lookup of Sockets for PHP get array with contents of getaddrinfo about the given hostname.

Syntax

socket_addrinfo_lookup(
    string $host,
    ?string $service = null,
    array $hints = []
): array|false

Parameters

host

Hostname to search.

service

The service to connect to. If service is a numeric string, it designates the port. Otherwise it designates a network service name, which is mapped to a port by the operating system.

hints

Hints provide criteria for selecting addresses returned. You may specify the hints as defined by getaddrinfo.

Return

Returns an array of AddressInfo instances that can be used with the other socket_addrinfo functions. On failure, false is returned.

Examples

1 · host

<?

$host = '127.0.0.1';

$return = socket_addrinfo_lookup($host);

print_r($return);

?>
Array
(
    [0] => AddressInfo Object
        (
        )

    [1] => AddressInfo Object
        (
        )

    [2] => AddressInfo Object
        (
        )

)

2 · service

<?

$host = '127.0.0.1';
$service = '5000';

$return = socket_addrinfo_lookup($host, $service);

print_r($return);

?>
Array
(
    [0] => AddressInfo Object
        (
        )

    [1] => AddressInfo Object
        (
        )

    [2] => AddressInfo Object
        (
        )

)

3 · hints

<?

$host = '127.0.0.1';
$service = '5000';
$hints =
[
    'ai_family' => 'AF_INET',
    'ai_socktype' => 'SOCK_STREAM'
];

$return = socket_addrinfo_lookup($host, $service, $hints);

print_r($return);

?>
Array
(
    [0] => AddressInfo Object
        (
        )

    [1] => AddressInfo Object
        (
        )

    [2] => AddressInfo Object
        (
        )

)
HomeMenu