This article lists all the functions that use socket-related services in the PHP language. Note that before using the following functions, you need to ensure that your socket is open. If you have not opened it, please edit your php.ini file and remove the comment (semicolon) in front of the following line:
The code is as follows:
extension=php_sockets.dll
If you cannot remove the comment, please use the following code to load the extension library:
The code is as follows:
if(!extension_loaded('sockets')){
if(strtoupper(substr(PHP_OS,3))=="WIN"){
dl('php_sockets.dll');
}else{
dl('sockets.so');
}
}
If you don’t know whether your socket is open, then you can use the phpinfo() function to determine whether the socket is open. You can check whether the socket is open by checking the phpinfo information.
php socket related functions are as follows:
The code is as follows:
Socket_accept() accepts a Socket connection
Socket_bind() binds the socket to an IP address and port
Socket_clear_error() clears the socket error or the last error code
Socket_close() closes a socket resource
socket_connect() starts a socket connection
socket_create_listen() opens a socket listening on the specified port
socket_create_pair() generates a pair of indistinguishable sockets into an array
Socket_create() generates a socket, which is equivalent to generating a socket data structure
socket_get_option() Gets socket options
Socket_getpeername() Gets the IP address of a remote similar host
Socket_getsockname() Gets the IP address of the local socket
socket_iovec_add() adds a new vector to a scatter/aggregate array
socket_iovec_alloc() This function creates an iovec data structure that can be sent, received, read and written
socket_iovec_delete() deletes an allocated iovec
Socket_iovec_fetch() returns the data of the specified iovec resource
Socket_iovec_free() releases an iovec resource
socket_iovec_set() sets the new value of iovec data
Socket_last_error() Gets the last error code of the current socket
Socket_listen() listens to all connections from the specified socket
socket_read() reads data of specified length
socket_readv() reads data from the scatter/aggregate array
Socket_recv() ends the data from the socket to the cache
Socket_recvfrom() accepts data from the specified socket. If not specified, it defaults to the current socket
Socket_recvmsg() receives messages from iovec
socket_select() Multiple selection
socket_send() This function sends data to the connected socket
socket_sendmsg() sends a message to socket
socket_sendto() sends a message to the socket at the specified address
socket_set_block() Set the socket to block mode
socket_set_nonblock() Set the socket to non-block mode
socket_set_option() Set socket options
Socket_shutdown() This function allows you to close reading, writing, or the specified socket
Socket_strerror() returns the detailed error of the specified error number
Socket_write() writes data to the socket cache
socket_writev() writes data to the scatter/aggregate array