PHP Socket Functions
EditRocket provides the following information on Socket functions in the PHP source code builder.
resource socket_accept ( resource $socket ) -
bool socket_bind ( resource $socket , string $address [, int $port ] ) - Binds the name given in address to the socket described by socket.
void socket_clear_error ([ resource $socket ] ) - This function clears the error code on the given socket or the global last socket error if no socket is specified.
void socket_close ( resource $socket ) - socket_close() closes the socket resource given by socket. This function is specific to sockets and cannot be used on any other type of resources.
bool socket_connect ( resource $socket , string $address [, int $port ] ) -
resource socket_create ( int $domain , int $type , int $protocol ) - Creates and returns a socket resource, also referred to as an endpoint of communication. A typical network connection is made up of 2 sockets, one performing the role of the client, and another performing the role of the server.
resource socket_create_listen ( int $port [, int $backlog ] ) - socket_create_listen() creates a new socket resource of type AF_INET listening on all local interfaces on the given port waiting for new connections.
bool socket_create_pair ( int $domain , int $type , int $protocol , array &$fd ) - socket_create_pair() creates two connected and indistinguishable sockets, and stores them in fd. This function is commonly used in IPC (InterProcess Communication).
mixed socket_get_option ( resource $socket , int $level , int $optname ) - The socket_get_option() function retrieves the value for the option specified by the optname parameter for the specified socket.
bool socket_getpeername ( resource $socket , string &$address [, int &$port ] ) - Queries the remote side of the given socket which may either result in host/port or in a Unix filesystem path, dependent on its type.
bool socket_getsockname ( resource $socket , string &$addr [, int &$port ] ) -
int socket_last_error ([ resource $socket ] ) - If a socket resource is passed to this function, the last error which occurred on this particular socket is returned. If the socket resource is omitted, the error code of the last failed socket function is returned.
bool socket_listen ( resource $socket [, int $backlog ] ) -
string socket_read ( resource $socket , int $length [, int $type ] ) -
int socket_recvfrom ( resource $socket , string &$buf , int $len , int $flags , string &$name [, int &$port ] ) - 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.
int socket_select ( array &$read , array &$write , array &$except , int $tv_sec [, int $tv_usec ] ) - socket_select() accepts arrays of sockets and waits for them to change status. Those coming with BSD sockets background will recognize that those socket resource arrays are in fact the so-called file descriptor sets. Three independent arrays of socket resources are watched.
int socket_send ( resource $socket , string $buf , int $len , int $flags ) - The function socket_send() sends len bytes to the socket socket from buf.
int socket_sendto ( resource $socket , string $buf , int $len , int $flags , string $addr [, int $port ] ) - The function socket_sendto() sends len bytes from buf through the socket socket to the port at the address addr.
bool socket_set_block ( resource $socket ) - The socket_set_block() function removes the O_NONBLOCK flag on the socket specified by the socket parameter.
bool socket_set_nonblock ( resource $socket ) - The socket_set_nonblock() function sets the O_NONBLOCK flag on the socket specified by the socket parameter.
bool socket_set_option ( resource $socket , int $level , int $optname , mixed $optval ) - The socket_set_option() function sets the option specified by the optname parameter, at the specified protocol level, to the value pointed to by the optval parameter for the socket.
bool socket_shutdown ( resource $socket [, int $how ] ) - The socket_shutdown() function allows you to stop incoming, outgoing or all data (the default) from being sent through the socket
string socket_strerror ( int $errno ) -
int socket_write ( resource $socket , string $buffer [, int $length ] ) - The function socket_write() writes to the socket from the given buffer.