Jesus · Bible · HTML · CSS · JS · PHP · SVG · Applications

socket_recvfrom

Description

Receives data from a socket whether or not it is connection-oriented

Syntax

socket_recvfrom(
    Socket $socket,
    string &$data,
    int $length,
    int $flags,
    string &$address,
    int &$port = null
): int|false

Parameters

socket

The socket must be a Socket instance previously created by socket_create().

data

The data received will be fetched to the variable specified with data.

length

Up to length bytes will be fetched from remote host.

flags

The value of flags can be any combination of the following flags, joined with the binary OR (|) operator.

ConstantDescription
MSG_OOBProcess out-of-band data.
MSG_PEEKReceive data from the beginning of the receive queue without removing it from the queue.
MSG_WAITALLBlock until at least length are received. However, if a signal is caught or the remote host disconnects, the function may return less data.
MSG_DONTWAITWith this flag set, the function returns even if it would normally have blocked.

address

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

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

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.

HomeMenu