socket_recvfrom
Receives data from a socket whether or not it is connection-oriented.
socket_recvfrom Function synopsis
socket_recvfrom(
Socket $socket,
&$data,
int $length,
int $flags,
&$address,
&$port = null
): int|false
Parameters
$socket
TypeSocket
The $socket must be a Socket instance previously
created by socket_create().
$data
Passed by reference
The data received will be fetched to the variable specified with
$data.
$length
Typeint
Up to $length bytes will be fetched from remote host.
$flags
Typeint
The value of $flags can be any combination of
the following flags, joined with the binary OR (|)
operator.
$flags accepts one or a bitmask of the following constant values:
$address
Passed by reference
If the socket is of the type AF_UNIX type,
$address is the path to the file. Else, for
unconnected sockets, $address is the IP address of,
the remote host, or null if the socket is connection-oriented.
$port
Passed by reference, OptionalDefault valuenull
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.
Note that the parameters
$data,$address, and$portare passed by reference, and contain additional/updated context data that may be useful.
Return value
Typeint|false
socket_recvfrom 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. This error code may be
passed to socket_strerror to get a textual explanation
of the error.
Changes to the socket_recvfrom Function
PHP 8.0
- Return type added:
int|false - Parameter type added for parameter #1 (
$socket):Socket - Parameter name of parameter #2 changed:
$bufto$data - Parameter name of parameter #3 changed:
$lento$length - Parameter type added for parameter #3 (
$length):int - Parameter type added for parameter #4 (
$flags):int - Parameter name of parameter #5 changed:
$nameto$address - Parameter default value added for position #6 (
$port):null
socket_recvfrom(
- $socket,
+ Socket $socket,
- &$buf,
+ &$data,
- $len,
+ int $length,
- $flags,
+ int $flags,
- &$name,
+ &$address,
- &$port
+ &$port = null
- )
+ ): int|false socket_recvfrom Function Availability
socket_recvfrom 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 |