public function readStanza()
    {
        $buff = '';

        if ($this->isConnected()) {
            $header = @socket_read($this->socket, 3); //read stanza header
           // if($header !== false && strlen($header) > 1){

            if ($header === false) {
                $this->eventManager()->fire('onClose',
                    [
                        $this->phoneNumber,
                        'Socket EOF',
                    ]
                );
            }
            if (strlen($header) == 0) {
                //no data received
                return;
            }
            if (strlen($header) != 3) {
                throw new ConnectionException('Failed to read stanza header');
            }
            $treeLength = (ord($header[0]) & 0x0F) << 16;
            $treeLength |= ord($header[1]) << 8;
            $treeLength |= ord($header[2]) << 0;

            //read full length
            $buff = socket_read($this->socket, $treeLength);
            //$trlen = $treeLength;
            $len = strlen($buff);
            //$prev = 0;
            while (strlen($buff) < $treeLength) {
                $toRead = $treeLength - strlen($buff);
                $buff .= socket_read($this->socket, $toRead);
                if ($len == strlen($buff)) {
                    //no new data read, fuck it
                    break;
                }
                $len = strlen($buff);
            }

            if (strlen($buff) != $treeLength) {
                throw new ConnectionException('Tree length did not match received length (buff = '.strlen($buff)." & treeLength = $treeLength)");
            }
            $buff = $header.$buff;
        }

        return $buff;
    }