Reference: http://www.cnblogs.com/thinksasa/archive/2013/02/26/2934206.html
http://blog.csdn.net/alongken2005/article/details/8056910
Socket_accept () is the server accepts client requests, and once a client link comes up, the function returns a new socket resource that is the resource that communicates with the client.
socket_accept () is blocked and will remain stuck there.
Discovery: Once the client disconnects, it affects the main process on the server. How to avoid this effect?
A normal server should be a new child process to process the request.
Socket_connect () is to link a socket to go. is used by the client.
C Language Introduction:Connect, send, recv are synchronous blocking mode of operation.
Then, it can be concluded that Socket_connect () is also obstructive.
Using the coprocessor in PHP:
Http://www.laruence.com/2015/05/28/3038.html
Socket_recv and Socket_read ($msgsock, 2048, Php_normal_read)
What difference does it have?
Stream_select ()
Accepts a socket stream, can be multiple, an array form.
Wait for these flows to change the state. A value greater than 0 is returned when the state is changed
<?php
/* Prepare the Read array */
$read = Array ($stream 1, $stream 2);//two sockets created
$write = NULL;
$except = NULL;
if (false = = = ($num _changed_streams = Stream_select ($read, $write, $except, 0))) {
/* Error Handling */
} elseif ($num _changed_streams > 0) {
/* At least on one of the streams something interesting happened */
}
?>
To use a reference pass, the value is modified.
PHP multiplexing Reference: http://blog.csdn.net/phphot/article/details/2020269
Summarize
If the socket extension is not installed, the following related functions are used: Stream_socket_client, Fread (), fwrite (), Stream_select (), fclose ()
If the Sokcet extension is installed , you can replace the extended function:
Stream_socket_client equivalent to Socket_create ()
Socket_select () equivalent to Stream_select ()
Socket_close () equivalent to fclose ()
Socket_write () equivalent to fwrite ()
Socket_read () equivalent to Fread ()
Stream_socket_client () is actually calling the connect () function of the Linux system.
Socket_select (), Stream_select () are all called the Select () functions provided by the operating system.
Thinking: What is the difference between stream and socket nature?
Don't know, think about to think about Socket_accept and Socket_listen () difference, perhaps can find the answer.
I always confuse socket_accept and Socket_listen ().
Socket_accept is the link that begins to accept the client, and if there is a client link, the function returns a handle to the socket, which is a handle specifically to the client. Socket_listen is starting to listen to this socket channel, just listening, not accepting the client's connection request.
Server-side listening port with PHP emulation