socket_recv
Description
The socket_recv of Sockets for PHP 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.
Constant | 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 length are received. However, if a signal is caught or the remote host disconnects, the function may return less data. |
MSG_DONTWAIT | With 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.
Links
Sockets
- socket_accept
- socket_addrinfo_bind
- socket_addrinfo_connect
- socket_addrinfo_explain
- socket_addrinfo_lookup
- socket_atmark
- socket_bind
- socket_clear_error
- socket_close
- socket_cmsg_space
- socket_connect
- socket_create
- socket_create_listen
- socket_create_pair
- socket_export_stream
- socket_get_option
- socket_getopt
- socket_getpeername
- socket_getsockname
- socket_import_stream
- socket_last_error
- socket_listen
- socket_read
- socket_recvfrom
- socket_recvmsg
- socket_select
- socket_send
- socket_sendmsg
- socket_sendto
- socket_set_block
- socket_set_nonblock
- socket_set_option
- socket_setopt
- socket_shutdown
- socket_strerror
- socket_write
- socket_wsaprotocol_info_export
- socket_wsaprotocol_info_import
- socket_wsaprotocol_info_release