Read the field length of a FastCGI name-value pair from a buffer.

@param string $buffer The buffer to read the field length from (pass by reference)

@return int The length of the field
199777
private function readFieldLength(string &$buffer): int
    {
        $block  = unpack('C4', $buffer);

        $length = $block[1];
        $skip   = 1;

        if ($length & 0x80) {
            $fullBlock = unpack('N', $buffer);
            $length    = $fullBlock[1] & 0x7FFFFFFF;
            $skip      = 4;
        }

        $buffer = substr($buffer, $skip);

        return $length;
    }
1093840
public function getBufferLength($atOffset = false)
    {
        if ($atOffset === false) {
            return $this->bufferLength;
        }

        return $this->bufferLength - $this->offset;
    }
782980
public function read($length)
    {
        if ($this->offset == $this->array_size) {
            return false;
        }

        // Don't use array slice
        $arrays = [];
        $end = $length + $this->offset;
        for ($i = $this->offset; $i < $end; ++$i) {
            if (!isset($this->array[$i])) {
                break;
            }
            $arrays[] = $this->array[$i];
        }
        $this->offset += $i - $this->offset; // Limit function calls
        $chars = false;
        foreach ($arrays as $array) {
            $chars .= implode('', array_map('chr', $array));
        }

        return $chars;
    }
717713
public function read($length)
    {
        if ($length < 1) {
            return '';
        }

        $buffer = fread($this->stream, $length);

        if ($buffer === false) {
            throw new RuntimeException('Failed to read ' . $length . ' bytes');
        }

        return $buffer;
    }
563538
public function getLength($input)
    {
        if (is_scalar($input)) {
            if ($this->countByChars) {
                return mb_strlen($input, $this->charset);
            } else {
                return strlen($input);
            }
        } elseif (is_array($input) || $input instanceof \Countable) {
            return count($input);
        } else {
            return false;
        }
    }
185726
protected function dataLength($temp)
   {
      if(count($temp) == 0) return 0;
      
      $arKeys = array_keys($temp);
      sort($arKeys);
      $dataLength = $arKeys[count($arKeys)-1];
      return $dataLength+1;
   }
373944
protected function processServerInfo(Buffer $buffer)
    {
        // Set the result to a new result instance
        $result = new Result();

        // Burn leading \ if one exists
        $buffer->readString('\\');

        // Key / value pairs
        while ($buffer->getLength()) {
            // Add result
            $result->add(
                trim($buffer->readString('\\')),
                utf8_encode(trim($buffer->readStringMulti(['\\', "\x0a"])))
            );
        }

        $result->add('password', 0);
        $result->add('mod', 0);

        unset($buffer);

        return $result->fetch();
    }
1322166
public static function parseFrame(string &$buffer): Record
    {
        $bufferLength = strlen($buffer);
        if ($bufferLength < FCGI::HEADER_LEN) {
            throw new \RuntimeException("Not enough data in the buffer to parse");
        }
        $recordHeader = unpack(FCGI::HEADER_FORMAT, $buffer);
        $recordType   = $recordHeader['type'];
        if (!isset(self::$classMapping[$recordType])) {
            throw new \DomainException("Invalid FCGI record type {$recordType} received");
        }

        /** @var Record $className */
        $className = self::$classMapping[$recordType];
        $record    = $className::unpack($buffer);


        $offset = FCGI::HEADER_LEN + $record->getContentLength() + $record->getPaddingLength();
        $buffer = substr($buffer, $offset);

        return $record;
    }
1207823
public static function input($buffer, TcpConnection $connection)
    {
        if (strlen($buffer) < 4) {
            return 0;
        }
        $unpack_data = unpack('Ntotal_length', $buffer);
        return $unpack_data['total_length'];
    }
320981
public function read($length)
    {
        if ($this->currentPos >= $this->charCount) {
            return false;
        }
        $ret = false;
        $length = ($this->currentPos + $length > $this->charCount) ? $this->charCount - $this->currentPos : $length;
        switch ($this->mapType) {
            case Swift_CharacterReader::MAP_TYPE_FIXED_LEN:
                $len = $length * $this->map;
                $ret = substr($this->datas,
                        $this->currentPos * $this->map,
                        $len);
                $this->currentPos += $length;
                break;

            case Swift_CharacterReader::MAP_TYPE_INVALID:
                $ret = '';
                for (; $this->currentPos < $length; ++$this->currentPos) {
                    if (isset($this->map[$this->currentPos])) {
                        $ret .= '?';
                    } else {
                        $ret .= $this->datas[$this->currentPos];
                    }
                }
                break;

            case Swift_CharacterReader::MAP_TYPE_POSITIONS:
                $end = $this->currentPos + $length;
                $end = $end > $this->charCount ? $this->charCount : $end;
                $ret = '';
                $start = 0;
                if ($this->currentPos > 0) {
                    $start = $this->map['p'][$this->currentPos - 1];
                }
                $to = $start;
                for (; $this->currentPos < $end; ++$this->currentPos) {
                    if (isset($this->map['i'][$this->currentPos])) {
                        $ret .= substr($this->datas, $start, $to - $start).'?';
                        $start = $this->map['p'][$this->currentPos];
                    } else {
                        $to = $this->map['p'][$this->currentPos];
                    }
                }
                $ret .= substr($this->datas, $start, $to - $start);
                break;
        }

        return $ret;
    }
141144
private function readRawCharsIntoBuffer($length)
    {
        $n = $length + 32;
        while ($this->bufferLength < $n) {
            $raw = $this->stream->read($n + 512);
            if ($raw === false || $raw === '') {
                return;
            }
            $this->buffer .= $raw;
            $this->bufferLength = $this->converter->getLength($this->buffer, $this->streamCharset);
        }
    }
205854
static function Length(&$text,$charset){
		$charset = self::_GetCharsetByName($charset);
		switch($charset){
			case "utf8":
				return self::_LengthUtf8($text);
			default:
				return strlen($text);
		}
	}
796940
public function getLength($field)
    {
        $type = $field['type'];
        if (($i = strpos($type, '(')) !== false) {
            $j = strpos($type, ')', $i);

            return substr($type, $i + 1, $j - $i - 1);
        }
        return 0;
    }
268676
public function consumeFrame(Buffer $buffer)
    {
        // not enough data
        if ($buffer->getLength() < 7) {
            return null;
        }

        $type = $buffer->readUint8(0);
        $channel = $buffer->readUint16(1);
        $payloadSize = $buffer->readUint32(3);
        $payloadOffset = 7; // type:uint8=>1 + channel:uint16=>2 + payloadSize:uint32=>4 ==> 7

        // not enough data
        if ($buffer->getLength() < $payloadOffset + $payloadSize + 1 /* frame end byte */) {
            return null;
        }

        $buffer->consume(7);
        $payload = $buffer->consume($payloadSize);
        $frameEnd = $buffer->consumeUint8();

        if ($frameEnd !== Constants::FRAME_END) {
            throw new ProtocolException(sprintf("Frame end byte invalid - expected 0x%02x, got 0x%02x.", Constants::FRAME_END, $frameEnd));
        }

        $frameBuffer = new Buffer($payload);

        if ($type === Constants::FRAME_METHOD) {
            $frame = $this->consumeMethodFrame($frameBuffer);

        } elseif ($type === Constants::FRAME_HEADER) {
            // see https://github.com/pika/pika/blob/master/pika/spec.py class BasicProperties
            $frame = new ContentHeaderFrame();
            $frame->classId = $frameBuffer->consumeUint16();
            $frame->weight = $frameBuffer->consumeUint16();
            $frame->bodySize = $frameBuffer->consumeUint64();
            $frame->flags = $flags = $frameBuffer->consumeUint16();

            if ($flags & ContentHeaderFrame::FLAG_CONTENT_TYPE) {
                $frame->contentType = $frameBuffer->consume($frameBuffer->consumeUint8());
            }

            if ($flags & ContentHeaderFrame::FLAG_CONTENT_ENCODING) {
                $frame->contentEncoding = $frameBuffer->consume($frameBuffer->consumeUint8());
            }

            if ($flags & ContentHeaderFrame::FLAG_HEADERS) {
                $frame->headers = $this->consumeTable($frameBuffer);
            }

            if ($flags & ContentHeaderFrame::FLAG_DELIVERY_MODE) {
                $frame->deliveryMode = $frameBuffer->consumeUint8();
            }

            if ($flags & ContentHeaderFrame::FLAG_PRIORITY) {
                $frame->priority = $frameBuffer->consumeUint8();
            }

            if ($flags & ContentHeaderFrame::FLAG_CORRELATION_ID) {
                $frame->correlationId = $frameBuffer->consume($frameBuffer->consumeUint8());
            }

            if ($flags & ContentHeaderFrame::FLAG_REPLY_TO) {
                $frame->replyTo = $frameBuffer->consume($frameBuffer->consumeUint8());
            }

            if ($flags & ContentHeaderFrame::FLAG_EXPIRATION) {
                $frame->expiration = $frameBuffer->consume($frameBuffer->consumeUint8());
            }

            if ($flags & ContentHeaderFrame::FLAG_MESSAGE_ID) {
                $frame->messageId = $frameBuffer->consume($frameBuffer->consumeUint8());
            }

            if ($flags & ContentHeaderFrame::FLAG_TIMESTAMP) {
                $frame->timestamp = $this->consumeTimestamp($frameBuffer);
            }

            if ($flags & ContentHeaderFrame::FLAG_TYPE) {
                $frame->typeHeader = $frameBuffer->consume($frameBuffer->consumeUint8());
            }

            if ($flags & ContentHeaderFrame::FLAG_USER_ID) {
                $frame->userId = $frameBuffer->consume($frameBuffer->consumeUint8());
            }

            if ($flags & ContentHeaderFrame::FLAG_APP_ID) {
                $frame->appId = $frameBuffer->consume($frameBuffer->consumeUint8());
            }

            if ($flags & ContentHeaderFrame::FLAG_CLUSTER_ID) {
                $frame->clusterId = $frameBuffer->consume($frameBuffer->consumeUint8());
            }

        } elseif ($type === Constants::FRAME_BODY) {
            $frame = new ContentBodyFrame();
            $frame->payload = $frameBuffer->consume($frameBuffer->getLength());

        } elseif ($type === Constants::FRAME_HEARTBEAT) {
            $frame = new HeartbeatFrame();
            if (!$frameBuffer->isEmpty()) {
                throw new ProtocolException("Heartbeat frame must be empty.");
            }

        } else {
            throw new ProtocolException("Unhandled frame type '{$type}'.");
        }

        if (!$frameBuffer->isEmpty()) {
            throw new ProtocolException("Frame buffer not entirely consumed.");
        }

        /** @var AbstractFrame $frame */
        $frame->type = $type;
        $frame->channel = $channel;
        $frame->payloadSize = $payloadSize;
        // DO NOT CALL! ContentBodyFrame uses payload for body
        // $frame->setPayload($payload);

        return $frame;
    }
995770
private function _getActualLength ( $text ) {
        $convertedText = $this->_convertTagsToEscapeSequences($text);
        $strippedText = $this->_stripEscapeSequences($convertedText);
        $length = mb_strlen($strippedText, 'utf-8');
        return $length;
    }
334742
public static function input($buffer)
    {
        if (strlen($buffer) < self::HEAD_LEN) {
            return 0;
        }
        $data = unpack("Npack_len", $buffer);
        return $data['pack_len'];
    }
1075273
public function readVarint(Stream $stream)
    {
        // Optimize common case (single byte varints)
        $byte = $this->readByte($stream);

        if ($byte < 0x80) {
            return $byte;
        }

        $length = $stream->getSize();
        $offset = $stream->tell();
        $result = $byte & 0x7f;
        $shift  = 7;

        // fastpath 32bit varints (5bytes) by unrolling the loop
        if ($length - $offset >= 4) {
            // 2
            $byte    = $this->readByte($stream);
            $result |= ($byte & 0x7f) << 7;

            if ($byte < 0x80) {
                return $result;
            }

            // 3
            $byte    = $this->readByte($stream);
            $result |= ($byte & 0x7f) << 14;

            if ($byte < 0x80) {
                return $result;
            }

            // 4
            $byte    = $this->readByte($stream);
            $result |= ($byte & 0x7f) << 21;

            if ($byte < 0x80) {
                return $result;
            }

            // 5
            $byte    = $this->readByte($stream);
            $result |= ($byte & 0x7f) << 28;

            if ($byte < 0x80) {
                return $result;
            }

            $shift = 35;
        }

        // If we're just at the end of the buffer or handling a 64bit varint
        do {
            $byte    = $this->readByte($stream);
            $result |= ($byte & 0x7f) << $shift;
            $shift  += 7;
        } while ($byte > 0x7f);

        return $result;
    }