public function acceptConnection($socket)
{
// Accept a connection on server socket.
$new_socket = @stream_socket_accept($socket, 0, $remote_address);
// Thundering herd.
if (!$new_socket) {
return;
}
// TcpConnection.
$connection = new TcpConnection($new_socket, $remote_address);
$this->connections = $connection;
$connection->worker = $this;
$connection->protocol = $this->protocol;
$connection->transport = $this->transport;
$connection->onMessage = $this->onMessage;
$connection->onClose = $this->onClose;
$connection->onError = $this->onError;
$connection->onBufferDrain = $this->onBufferDrain;
$connection->onBufferFull = $this->onBufferFull;
// Try to emit onConnect callback.
if ($this->onConnect) {
try {
call_user_func($this->onConnect, $connection);
} catch (\Exception $e) {
self::log($e);
exit(250);
} catch (\Error $e) {
self::log($e);
exit(250);
}
}
}
這個(gè) “ stream_socket_accept”” 這里會(huì)報(bào)出錯(cuò)誤 stream_socket_accept(): accept failed: Resource temporarily unavailable
在群里問(wèn)了說(shuō)是不影響。但是還是想知道為什么
stream_socket_accept是從系統(tǒng)連接隊(duì)列里獲取一個(gè)socket連接,這個(gè)操作不一定成功,比如有其它進(jìn)程已經(jīng)調(diào)用stream_socket_accept把最后一個(gè)socket從隊(duì)列里取出,當(dāng)前進(jìn)程調(diào)用就返回失敗,可能會(huì)觸發(fā)一個(gè)waring,但是這個(gè)并不影響。而且workerman源碼里用@抑制了錯(cuò)誤。
恩懂了。是我用 error_get_last 的時(shí)候獲取了這個(gè)錯(cuò)誤有這個(gè)疑問(wèn),所以想問(wèn)個(gè)清楚謝謝大大。