src/mg/Ding/Helpers/Tcp/TcpClientHelper.php
public function process()
    {
        if ($this->_socket === false || !$this->_connected) {
            return;
        }
        $read = array($this->_socket);
        $write = null;
        $ex = null;
        $result = @socket_select($read, $write, $ex, 0, 1);
        if ($result === false) {
            throw new TcpException(
            	'Error selecting from socket: '
                . socket_strerror(socket_last_error($this->_socket))
            );
        }
        if ($result > 0) {
            if (in_array($this->_socket, $read)) {
                $buffer = '';
                $len = 1;
                $len = $this->read($buffer, $len, true);
                if ($len > 0) {
                    if ($len >= $this->_readLen) {
                        $this->_lastDataReadTime = $this->getMicrotime();
                        $this->_handler->data();
                        return;
                    }
                } else {
                    $this->close();
                    return;
                }
            }
        }
        $now = $this->getMicrotime();
        if (($now - $this->_lastDataReadTime) > $this->_rTo) {
            if ($this->_rTo > 0) {
                $this->_handler->readTimeout();
            }
            $this->_lastDataReadTime = $now;
        }
    }
public function process()
    {
        if ($this->_socket === false || !$this->_connected) {
            return;
        }
        $read = array($this->_socket);
        $write = null;
        $ex = null;
        $result = @socket_select($read, $write, $ex, 0, 1);
        if ($result === false) {
            throw new TcpException(
            	'Error selecting from socket: '
                . socket_strerror(socket_last_error($this->_socket))
            );
        }
        if ($result > 0) {
            if (in_array($this->_socket, $read)) {
                $buffer = '';
                $len = 1;
                $len = $this->read($buffer, $len, true);
                if ($len > 0) {
                    if ($len >= $this->_readLen) {
                        $this->_lastDataReadTime = $this->getMicrotime();
                        $this->_handler->data();
                        return;
                    }
                } else {
                    $this->close();
                    return;
                }
            }
        }
        $now = $this->getMicrotime();
        if (($now - $this->_lastDataReadTime) > $this->_rTo) {
            if ($this->_rTo > 0) {
                $this->_handler->readTimeout();
            }
            $this->_lastDataReadTime = $now;
        }
    }
Main reading loop. Call this in your own infinite loop or declare(ticks)
in your software. This routine will call your client handler when there
is data available to read. Will always detect when the other side closed
the connection.

@return void