SOCKET_GETSOCKNAME(3) 1 SOCKET_GETSOCKNAME(3)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 typeSYNOPSIS
bool socket_getsockname (resource $socket, string &$addr, [int &$port])
DESCRIPTION
Note
socket_getsockname(3) should not be used with AF_UNIX sockets created with socket_connect(3). Only sockets created with
socket_accept(3) or a primary server socket following a call to socket_bind(3) will return meaningful values.
PARAMETERS
o $socket
- A valid socket resource created with socket_create(3) or socket_accept(3).
o $addr
- If the given socket is of type AF_INET or AF_INET6, socket_getsockname(3) will return the local IP address in appropriate nota-
tion (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. If the given socket is of type AF_UNIX, socket_getsockname(3) will return the Unix filesystem path (e.g. /var/run/dae-
mon.sock) in the $address parameter.
o $port
- If provided, this will hold the associated port.
RETURN VALUES
Returns TRUE on success or FALSE on failure. socket_getsockname(3) 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.
SEE ALSO socket_getpeername(3), socket_last_error(3), socket_strerror(3).
PHP Documentation Group SOCKET_GETSOCKNAME(3)
Check Out this Related Man Page
SOCKET_RECVFROM(3) 1 SOCKET_RECVFROM(3)socket_recvfrom - Receives data from a socket whether or not it is connection-orientedSYNOPSIS
int socket_recvfrom (resource $socket, string &$buf, int $len, int $flags, string &$name, [int &$port])
DESCRIPTION
The socket_recvfrom(3) function receives $len bytes of data in $buf from $name on port $port (if the socket is not of type AF_UNIX) using
$socket. socket_recvfrom(3) can be used to gather data from both connected and unconnected sockets. Additionally, one or more flags can be
specified to modify the behaviour of the function.
The $name and $port must be passed by reference. If the socket is not connection-oriented, $name will be set to the internet protocol
address of the remote host or the path to the UNIX socket. If the socket is connection-oriented, $name is NULL. Additionally, the $port
will contain the port of the remote host in the case of an unconnected AF_INET or AF_INET6 socket.
PARAMETERS
o $socket
- The $socket must be a socket resource previously created by socket_create().
o $buf
- The data received will be fetched to the variable specified with $buf.
o $len
- Up to $len bytes will be fetched from remote host.
o $flags
- The value of $flags can be any combination of the following flags, joined with the binary OR ( |) operator.
Possible values for $flags
+-------------+---------------------------------------------------+
| Flag | |
| | |
| | Description |
| | |
+-------------+---------------------------------------------------+
| | |
| MSG_OOB | |
| | |
| | Process out-of-band data. |
| | |
| | |
| MSG_PEEK | |
| | |
| | Receive data from the beginning of the receive |
| | queue without removing it from the queue. |
| | |
| | |
|MSG_WAITALL | |
| | |
| | Block until at least $len are received. However, |
| | if a signal is caught or the remote host discon- |
| | nects, the function may return less data. |
| | |
| | |
|MSG_DONTWAIT | |
| | |
| | With this flag set, the function returns even if |
| | it would normally have blocked. |
| | |
+-------------+---------------------------------------------------+
o $name
- If the socket is of the type AF_UNIX type, $name is the path to the file. Else, for unconnected sockets, $name is the IP address
of, the remote host, or NULL if the socket is connection-oriented.
o $port
- This argument only applies to AF_INET and AF_INET6 sockets, and specifies the remote port from which the data is received. If
the socket is connection-oriented, $port will be NULL.
RETURN VALUES socket_recvfrom(3) returns the number of bytes received, or FALSE if there was an error. The actual error code can be retrieved by calling
socket_last_error(3). This error code may be passed to socket_strerror(3) to get a textual explanation of the error.
EXAMPLES
Example #1
socket_recvfrom(3) example
<?php
error_reporting(E_ALL | E_STRICT);
$socket = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
socket_bind($socket, '127.0.0.1', 1223);
$from = '';
$port = 0;
socket_recvfrom($socket, $buf, 12, 0, $from, $port);
echo "Received $buf from remote address $from and remote port $port" . PHP_EOL;
?>
This example will initiate a UDP socket on port 1223 of 127.0.0.1 and print at most 12 characters received from a remote host.
CHANGELOG
+--------+----------------------------------------+
|Version | |
| | |
| | Description |
| | |
+--------+----------------------------------------+
| 4.3.0 | |
| | |
| | socket_recvfrom(3) is now binary safe. |
| | |
+--------+----------------------------------------+
SEE ALSO socket_recv(3), socket_send(3), socket_sendto(3), socket_create(3).
PHP Documentation Group SOCKET_RECVFROM(3)