socket_getpeername
Queries the remote side of the given socket.
socket_getpeername Function synopsis
socket_getpeername(
Socket $socket,
&$address,
&$port = null
): bool
Parameters
$socket
TypeSocket
A Socket instance created with socket_create
or socket_accept.
$address
Passed by reference
If the given socket is of type AF_INET or
AF_INET6, socket_getpeername
will return the peers (remote) IP address in
appropriate notation (e.g. 127.0.0.1 or
fe80::1) in the $address
parameter and, if the optional $port parameter is
present, also the associated port.
$port
Passed by reference, OptionalDefault valuenull
If given, this will hold the port associated to
$address.
Note that the parameters
$addressand$portare passed by reference, and contain additional/updated context data that may be useful.
Return value
Typebool
Returns true on success, false on failure socket_getpeername may also return
false if the socket type is not any of AF_INET,
AF_INET6, or AF_UNIX, in which
case the last socket error code is not updated.
Changes to the socket_getpeername Function
PHP 8.0
- Return type added:
bool - Parameter type added for parameter #1 (
$socket):Socket - Parameter name of parameter #2 changed:
$addrto$address - Parameter default value added for position #3 (
$port):null
socket_getpeername(
- $socket,
+ Socket $socket,
- &$addr,
+ &$address,
- &$port
+ &$port = null
- )
+ ): bool socket_getpeername Function Availability
socket_getpeername Function Availability| PHP Version | Availability |
|---|---|
| PHP 8.6Upcoming Release | Yes |
| PHP 8.5Supported (Latest) | Yes |
| PHP 8.4Supported | Yes |
| PHP 8.3Security-Fixes Only | Yes |
| PHP 8.2Security-Fixes Only | Yes |
| PHP 8.1Unsupported | Yes |
| PHP 8.0Unsupported | Yes |
| PHP 7.4Unsupported | Yes |
| PHP 7.3Unsupported | Yes |
| PHP 7.2Unsupported | Yes |
| PHP 7.1Unsupported | Yes |
| PHP 7.0Unsupported | Yes |
| PHP 5.6Unsupported | Yes |
| PHP 5.5Unsupported | Yes |
| PHP 5.4Unsupported | Yes |
| PHP 5.3Unsupported | Yes |