Looking at socket, a lot of things are unclear. a html5 & nbsp; socket & nbsp; is sent to php. serverphp. some of the server's code functions & nbsp ;__ construct & nbsp; ($ address, & nbsp; $ port) & nbsp; {erro doesn't understand many things about socket.
I sent an html5 socket to php. server.
Php. server does not understand anything.
Some code
function __construct ($address, $port) {
error_reporting (E_ALL);
set_time_limit (0);
ob_implicit_flush ();
// Socket creation
$this->master = socket_create (AF_INET, SOCK_STREAM, SOL_TCP) or die("socket_create() failed");
socket_set_option ($this->master, SOL_SOCKET, SO_REUSEADDR, 1) or die("socket_option() failed");
socket_bind ($this->master, $address, $port) or die("socket_bind() failed");
socket_listen ($this->master, 20) or die("socket_listen() failed");
$this->sockets[] = $this->master;
$this->say ("Server Started : " . date ('Y-m-d H:i:s'));
$this->say ("Listening on : {$address} {$port}");
$this->say ("Master socket : {$this->master}\n");
// Main loop
while (true) {
$changed = $this->sockets;
socket_select ($changed, $write = NULL, $except = NULL, NULL);
foreach ($changed as $socket) {
if ($socket == $this->master) {
$client = socket_accept ($this->master);
if ($client < 0) {
$this->log ("socket_accept() failed");
continue;
}
else {
// Connects the socket
$this->connect ($client);
}
}
else {
$bytes = @socket_recv ($socket, $buffer, 2048, 0);
if ($bytes == 0) {
// On socket.close ();
$this->disconnect ($socket);
}
else {
// Retrieve the user from his socket
$user = $this->getuserbysocket ($socket);
if (!$user->handshake) {
$this->dohandshake ($user, $buffer);
}
else {
$this->process ($user, $this->decode ($buffer));
}
}
}
}
}
}
I am running server. php server. php in linux.
I found
Socket_select ($ changed, $ write = NULL, $ Partition T = NULL, NULL );
It won't run down.
I checked socket_select online.
Address is http://php.net/manual/en/function.socket-select.php
Socket_select-Runs the select () system call on the given arrays of sockets with a specified timeout
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.
According to my understanding, this socket_select can listen to changes in the status of things in the sockets array.
When the status does not change, it is suspended and will not be executed.
Is that true?
------ Solution --------------------
Socket_select () is the end of waiting for all connections to have new dynamics. it has a timeout parameter that specifies how long it can be blocked (which can be understood as running. If the input value is NULL, the function will end after all listening objects have new connections.