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

socket_recv

Description

Receives data from a connected socket

Syntax

socket_recv(
    Socket $socket,
    ?string &$data,
    int $length,
    int $flags
): 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. If an error occurs, if the connection is reset, or if no data is available, data will be set to null.

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.

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