OpenSwoole\Coroutine\Client->getPeerName()

Latest version: pecl install openswoole-22.1.2 | composer require openswoole/core:22.1.5

Declaration

<?php OpenSwoole\Coroutine\Client->getPeerName(): array|false

Parameters

None

Return

Returns an array of a connected peer, showing its host and port that is being used by the socket.

Description

Obtain the IP address and port of the opposite socket.

Only supported when the client type is:

  • OpenSwoole\Constant::SOCK_UDP
  • OpenSwoole\Constant::SOCK_UDP6
  • OpenSwoole\Constant::SOCK_UNIX_DGRAM

This function can be used to obtain a UDP peer IP and port, after calling $client->recv(). Because a client sends data to the server, a response may not be given, so this method can be used when needing to know the peer IP and port.

Example

<?php

var_dump($client->getPeerName());

...

// Output
[
    'host' => '127.0.0.1', 'port' => 53653,
]
Last updated on September 20, 2022