Metaregistrar\EPP\eppBase::read PHP 메소드

read() 공개 메소드

This will read 1 response from the connection if there is one
public read ( boolean $nonBlocking = false ) : string
$nonBlocking boolean to prevent the blocking of the thread in case there is nothing to read and not wait for the timeout
리턴 string
    public function read($nonBlocking = false)
    {
        putenv('SURPRESS_ERROR_HANDLER=1');
        $content = '';
        $time = time() + $this->timeout;
        $read = "";
        while (!isset($length) || $length > 0) {
            if (feof($this->connection)) {
                putenv('SURPRESS_ERROR_HANDLER=0');
                throw new eppException('Unexpected closed connection by remote host...', 0, null, null, $read);
            }
            //Check if timeout occured
            if (time() >= $time) {
                putenv('SURPRESS_ERROR_HANDLER=0');
                return false;
            }
            //If we dont know how much to read we read the first few bytes first, these contain the content-length
            //of whats to come
            if (!isset($length) || $length == 0) {
                $readLength = 4;
                //$readbuffer = "";
                $read = "";
                while ($readLength > 0) {
                    if ($readbuffer = fread($this->connection, $readLength)) {
                        $readLength = $readLength - strlen($readbuffer);
                        $read .= $readbuffer;
                        $time = time() + $this->timeout;
                    }
                    //Check if timeout occured
                    if (time() >= $time) {
                        putenv('SURPRESS_ERROR_HANDLER=0');
                        return false;
                    }
                }
                //$this->writeLog("Read 4 bytes for integer. (read: " . strlen($read) . "):$read","READ");
                $length = $this->readInteger($read) - 4;
                $this->writeLog("Reading next: {$length} bytes", "READ");
            }
            if ($length > 1000000) {
                throw new eppException("Packet size is too big: {$length}. Closing connection", 0, null, null, $read);
            }
            //We know the length of what to read, so lets read the stuff
            if (isset($length) && $length > 0) {
                $time = time() + $this->timeout;
                if ($read = fread($this->connection, $length)) {
                    //$this->writeLog(print_R(socket_get_status($this->connection), true));
                    $length = $length - strlen($read);
                    $content .= $read;
                    $time = time() + $this->timeout;
                }
                if (strpos($content, 'Session limit exceeded') > 0) {
                    $read = fread($this->connection, 4);
                    $content .= $read;
                }
            }
            if ($nonBlocking && strlen($content) < 1) {
                //there is no content don't keep waiting
                break;
            }
            if (!strlen($read)) {
                usleep(100);
            }
        }
        putenv('SURPRESS_ERROR_HANDLER=0');
        #ob_flush();
        return $content;
    }