接收数据
@param int $length 接收数据的长度
@param bool $waitall 等待接收到全部数据后再返回，注意这里超过包长度会阻塞住
@return string | bool
496947
function recv($length = 65535, $waitall = false)
    {
        $flags = 0;
        if ($waitall)
        {
            $flags = MSG_WAITALL;
        }

        $ret = socket_recv($this->sock, $data, $length, $flags);
        if ($ret === false)
        {
            $this->set_error();
            //重试一次，这里为防止意外，不使用递归循环
            if ($this->errCode == 4)
            {
                socket_recv($this->sock, $data, $length, $waitall);
            }
            else
            {
                return false;
            }
        }
        return $data;
    }
1017997
public static function getRandomString(int $length = 64) : string
    {
        $characters = "01234567890123456789";
        $characters .= "abcdefghijklmnopqrstuvwxyz";

        $string_generated = "";

        while ($length--) {
            $string_generated .= $characters[mt_rand(0, 45)];
        }

        return $string_generated;
    }
134865
public static function salts($length)
    {
        $chars = array_merge(range(0, 9), range('a', 'z'), range('A', 'Z'));
        $stringlength = count($chars); //Used Count because its array now
        $randomString = '';
        for ($i = 0; $i < $length; $i++) {
            $randomString .= $chars[rand(0, $stringlength - 1)];
        }

        return $randomString;
    }
1105393
public function fgets( $length = null )
    {
        return $this->validHandle() ? fgets( $this->_fileHandle, $length ) : false;
    }
1329433
static function GetRandomPassPhrase($length = 8)
	{
		srand((double)microtime()*1000000);
		
		$vowels = array("a", "e", "i", "o", "u");
		$cons = array("b", "c", "d", "g", "h", "j", "k", "l", "m", "n", "p", "r", "s", "t", "u", "v", "w", "tr",
			"cr", "br", "fr", "th", "dr", "ch", "ph", "wr", "st", "sp", "sw", "pr", "sl", "cl");
		$badwords = array("fuc","shit","ass","pus","slut","dic","fag","coc","cun","cum","dam","nig","kik","spic","neg","bitc","gay","poo","twa","vag","peni","whor");
		
		$num_vowels = count($vowels);
		$num_cons = count($cons);
		$password = "";
		
		for($i = 0; $i < $length; $i++)
		{
			$password .= $cons[rand(0, $num_cons - 1)] . $vowels[rand(0, $num_vowels - 1)];
		}
		
		$newpass = substr($password, 0, $length);
		
		// ensure this is not a potentially offensive password
		foreach ($badwords as $badword)
		{
			if ( strpos($newpass,$badword) !== false)
			{
				return PassPhrase::GetRandomPassPhrase($length);
			}
		}
		
		return $newpass;
	}
215039
public static function getRandomString(int $length): string {
		
		// list of available chars for random string
		$availableChars = '123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVXYWZ';
		
		// create a random string
		return substr(str_shuffle($availableChars . $availableChars), 0, $length);
		
	}
659547
public function generate($length)
    {
        $realPool = $this->mergePools($this->characterPools);
        $max = (count($realPool) - 1);
        mt_srand();

        $randomString = '';

        for ($i = 0; $i < $length; $i++) {
            $randomString .= $realPool[mt_rand(0, $max)];
        }

        return $randomString;
    }
1319845
public function read($length)
	{
		$read = 0;
		$parts = array();

		while ($read < $length && !$this->_wrapper()->feof($this->_socket))
		{
			$data = $this->_wrapper()
				->fread($this->_socket, $length - $read);

			if ($data === false)
			{
				throw new Pheanstalk_Exception_SocketException('fread() returned false');
			}

			$read += strlen($data);
			$parts []= $data;
		}

		return implode($parts);
	}
1364120
private function childParseFromArray($length = 99999999)
    {
        $_begin = $this->reader->getPointer();
        while ($this->reader->getPointer() - $_begin < $length) {
            $next = $this->reader->next();
            if ($next === false) {
                break;
            }

            // now get the message type
            $messtypes = $this->getTypes($next);

            // now make method test
            if (!array_key_exists($messtypes['field'], $this->fields)) {
                // field is unknown so just ignore it
                // throw new \Exception('Field ' . $messtypes['field'] . ' not present ');
                if ((int) $messtypes['wired'] === PBMessage::WIRED_LENGTH_DELIMITED) {
                    $consume = new PBString($this->reader);
                } elseif ((int) $messtypes['wired'] === PBMessage::WIRED_VARINT) {
                    $consume = new PBInt($this->reader);
                } else {
                    throw new \InvalidArgumentException('I dont understand this wired code:' . $messtypes['wired']);
                }

                // perhaps send a warning out
                // @TODO SEND CHUNK WARNING
                $_oldpointer = $this->reader->getPointer();
                $consume->parseFromArray();
                // now add array from _oldpointer to pointer to the chunk array
                $this->chunk .= $this->reader->getMessageFrom($_oldpointer);
                continue;
            }

            // now array or not
            if (is_array($this->values[$messtypes['field']])) {
                $this->values[$messtypes['field']][] = new $this->fields[$messtypes['field']]($this->reader);
                $index = count($this->values[$messtypes['field']]) - 1;
                if ($messtypes['wired'] !== $this->values[$messtypes['field']][$index]->wired_type) {
                    throw new \InvalidArgumentException('Expected type:' . $messtypes['wired']
                        . ' but had ' . $this->fields[$messtypes['field']]->wired_type);
                }
                if (method_exists($this->values[$messtypes['field']][$index], 'parseFromArray')) {
                    $this->values[$messtypes['field']][$index]->parseFromArray();
                }
            } else {
                $this->values[$messtypes['field']] = new $this->fields[$messtypes['field']]($this->reader);
                if ($messtypes['wired'] !== $this->values[$messtypes['field']]->wired_type) {
                    throw new \InvalidArgumentException('Expected type:' . $messtypes['wired']
                        . ' but had ' . $this->fields[$messtypes['field']]->wired_type);
                }
                if (method_exists($this->values[$messtypes['field']], 'parseFromArray')) {
                    $this->values[$messtypes['field']]->parseFromArray();
                }
            }
        }
    }
859462
public static function randStr($type, $length = 6)
    {
        // TODO 生成随机长度的字符串
        if ($type == self::ALPHABET) {
            return self::randAlphabet($length);
        } elseif ($type == self::ALPHABET_AND_NUMBERS) {
            return self::randAlphabetAndNumbers($length);
        } elseif ($type == self::NUMBERS) {
            return self::randNumbers($length);
        }

        return "unknown type";
    }
40063
public function string(int $length = 8)
    {
        $list = 'abcdefghijklmnopqrstuvwxyz';
        $return = '';
        for ($i = 0; $i < $length; $i++) {
            $return .= $list[rand(0, strlen($list) - 1)];
        }

        return $return;
    }
1213418
public function read($length)
    {
        // let Guzzle decide what to do.
        if ($length <= 0 || $this->eof()) {
            return $this->stream->read($length);
        }
        $this->readRawCharsIntoBuffer($length);
        $numChars = min([$this->bufferLength, $length]);
        $chars = $this->converter->getSubstr($this->buffer, $this->streamCharset, 0, $numChars);
        
        $this->position += $numChars;
        $this->buffer = $this->converter->getSubstr($this->buffer, $this->streamCharset, $numChars);
        $this->bufferLength = $this->bufferLength - $numChars;

        return $this->converter->convert($chars, $this->streamCharset, $this->stringCharset);
    }
1339035
static function string($length = 8, $number = true, $ignore = array('0', 'o', 'l', '1', 'i'))
    {
        $strings = 'ABCDEFGHIJKLOMNOPQRSTUVWXYZ';  //字符池
        $numbers = '0123456789';                    //数字池
        if ($ignore and is_array($ignore))
        {
            $strings = str_replace($ignore, '', $strings);
            $numbers = str_replace($ignore, '', $numbers);
        }

        $pattern = $strings . $numbers;
        $max = strlen($pattern) - 1;
        $key = '';
        for ($i = 0; $i < $length; $i++)
        {
            $key .= $pattern[mt_rand(0, $max)];    //生成php随机数
        }
        return $key;
    }
1078518
static function getRandomString($length = 8)
    {

        $chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';

        $value = '';
        $charsLength = strlen($chars) - 1;

        for ($i = 1 ; $i <= $length; $i++) {
            $value .= $chars[rand(0, $charsLength)];
        }

        return $value;

    }
77498
public function read($length = 4096)
    {
        $data = false;
        $this->_checkFileOpened();
        if ($length > 0) {
            $data = $this->_read($length);
        }

        return $data;
    }
1149344
public function asString(StringLength $length = null)
    {
        return $this->handleFilter(
                function() use($length)
                {
                    return filter\RangeFilter::wrap(
                            filter\StringFilter::instance(),
                            $length
                    );
                }
        );
    }
132872
public static function isXhtmlLength($length)
    {
        if (is_int($length) === true) {
            return $length >= 0;
        } elseif (is_string($length) === true) {
            return preg_match("/[0-9]+%/", $length) === 1;
        } else {
            return false;
        }
    }