socket_getsockname
Queries the local side of the given socket which may either result in host/port or in a Unix filesystem path, dependent on its type.
socket_getsockname Function synopsis
socket_getsockname(
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_getsockname
will return the local 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 provided, this will hold the associated port.
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_getsockname 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_getsockname 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_getsockname(
- $socket,
+ Socket $socket,
- &$addr,
+ &$address,
- &$port
+ &$port = null
- )
+ ): bool socket_getsockname Function Availability
socket_getsockname 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 |