In PHP to send data to other programs, you need to use the socket function to the PHP instance, below we briefly look at an example
| code as follows |
copy code |
|
/*socket send and receive Data
@host (String) Socket server IP
@post (int) port
@str (String) data to be sent
@back 1|0 socket port for data return
return true|false| server Data
*/
function sendsocketmsg ($host, $port, $str, $back =0) {
$socket = socket_create (af_inet,sock_stream,0);
if ($ Socket < 0) return false;
$result = @socket_connect ($socket, $host, $port);
if ($result = = false) return false;
Socket_write ($socket, $str, strlen ($STR));
if ($back!=0) {
$input = Socket_read ($socket, 1024x768);
Socket_close ($socket);
return $input;
}else{
Socket_close ($socket);
return true;
}
} |
The second parameter of the Socker_read specifies the number of bytes to read, which you can use to limit the size of the data fetched from the client.
Sock function Introduction
Socket function
Function Name Description
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 () Close a socket resource
Socket_connect () Start a socket connection
Socket_create_listen () Open a socket listener on the specified port
Socket_create_pair () produces a pair of indistinguishable sockets into an array
Socket_create () produces a socket equivalent to a data structure that produces a socket
Socket_get_option () Get 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 () Add a new vector to a scatter/aggregate array
Socket_iovec_alloc () This function creates a IOVEC data structure that can send the received read and write
Socket_iovec_delete () Delete an already assigned Iovec
Socket_iovec_fetch () returns the data for the specified Iovec resource
Socket_iovec_free () releasing a Iovec resource
Socket_iovec_set () Sets the new data value of the Iovec
Socket_last_error () Gets the last error code for the current socket
Socket_listen () listens for all connections by the specified socket
Socket_read () reads the specified length of data
SOCKET_READV () reads data from a scatter/aggregate array
SOCKET_RECV () end data from socket to cache
Socket_recvfrom () accepts data from the specified socket, if not specified, the default current socket
Socket_recvmsg () receive messages from Iovec
Socket_select () multi-channel selection
Socket_send () This function sends the data to the connected socket
SOCKET_SENDMSG () Send message to socket
Socket_sendto () sends a message to the socket at the specified address
Socket_set_block () set as block mode in socket
Socket_set_nonblock () set to non-block mode in socket
Socket_set_option () Set socket options
Socket_shutdown () This function allows you to close a read, write, or specified socket
Socket_strerror () returns a detailed error for the specified error number
Socket_write () write data to the socket cache
Socket_writev () write data to a scatter/aggregate array
Note: The Socket_read function reads the shell data until the n,t or characters are met, and the PHP script considers the characters as the Terminator of the input.
http://www.bkjia.com/PHPjc/444627.html www.bkjia.com true http://www.bkjia.com/PHPjc/444627.html techarticle in PHP to send data to other programs, you need to use the socket function to the PHP instance, below we simply look at an example code as follows copy code/*socket send and receive Data @host (Stri ...