Home > PHP > Function > Sockets > socket_recvfrom()

socket_recvfrom()

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

Syntax

int socket_recvfrom (resource $socket, string &$buf, int $len, int $flags, string &$name, int &$port)

Arguments

  • socket - The socket must be a socket resource previously created by socket_create().
  • buf - The data received will be fetched to the variable specified with buf.
  • len - Up to len 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. 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 disconnects, the function may return less data. MSG_DONTWAIT With this flag set, the function returns even if it would normally have blocked.
  • 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.
  • 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.

Description

The socket_recvfrom() 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() 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.

Version

PHP 4.1.0, 5

Return value

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.