本文整理汇总了PHP中zlib_encode函数的典型用法代码示例。如果您正苦于以下问题:PHP zlib_encode函数的具体用法?PHP zlib_encode怎么用?PHP zlib_encode使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了zlib_encode函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: onRun
public function onRun()
{
try {
$this->final = zlib_encode($this->data, ZLIB_ENCODING_DEFLATE, $this->level);
$this->data = null;
} catch (\Throwable $e) {
}
}
开发者ID:Marttinek,项目名称:Genisys,代码行数:8,代码来源:CompressBatchedTask.php
示例2: onRun
public function onRun()
{
try {
$this->final = \zlib_encode($this->data, ZLIB_ENCODING_DEFLATE, $this->level);
$this->data = \null;
} catch (\Exception $e) {
}
}
开发者ID:kazuemon,项目名称:NIGHTMARE,代码行数:8,代码来源:CompressBatchedTask.php
示例3: encode
/**
*
*/
static function encode($data)
{
$compressedData = zlib_encode($data, ZLIB_ENCODING_DEFLATE);
if ($compressedData) {
return base64_encode($compressedData);
}
return false;
}
开发者ID:citypay,项目名称:php-sdk,代码行数:11,代码来源:ThreeDSecureUtils.php
示例4: saveSkin
public function saveSkin($human, $fn, $folder = null)
{
if ($folder === null) {
$folder = $this->owner->getDataFolder();
}
$bin = zlib_encode($human->getSkinData(), ZLIB_ENCODING_DEFLATE, 9);
file_put_contents($folder . $fn, $bin);
return strlen($bin);
}
开发者ID:0-DevMatthew-0,项目名称:pocketmine-plugins,代码行数:9,代码来源:CmdSkinner.php
示例5: encode
public function encode($data = '', $level = -1, $encoding = ZLIB_ENCODING_GZIP)
{
if (!is_scalar($data)) {
return Error::set('Error', 'valueParameter', '1.(data)');
}
if (!is_numeric($level) || !is_numeric($encoding)) {
return Error::set('Error', 'numericParameter', '2.(level) & 3.(encoding)');
}
return zlib_encode($data, $encoding, $level);
}
开发者ID:bytemtek,项目名称:znframework,代码行数:10,代码来源:ZLIB.php
示例6: onRun
public function onRun()
{
$old = json_decode(zlib_decode(file_get_contents($this->path)));
if (is_object($old)) {
$time = $old->registerTime;
if ($time !== -1) {
$this->isReg = false;
}
}
file_put_contents($this->path, zlib_encode($this->contents, ZLIB_ENCODING_DEFLATE));
}
开发者ID:GoneTone,项目名称:HereAuth,代码行数:11,代码来源:JsonSaveDataTask.php
示例7: encodeData
private function encodeData()
{
$this->addLine();
$this->addLine("----------------------REPORT THE DATA BELOW THIS LINE-----------------------");
$this->addLine();
$this->addLine("===BEGIN CRASH DUMP===");
$this->encodedData = zlib_encode(json_encode($this->data, JSON_UNESCAPED_SLASHES), ZLIB_ENCODING_DEFLATE, 9);
foreach (str_split(base64_encode($this->encodedData), 76) as $line) {
$this->addLine($line);
}
$this->addLine("===END CRASH DUMP===");
}
开发者ID:ecoron,项目名称:MinionsLandPE,代码行数:12,代码来源:CrashDump.php
示例8: write
public function write(AccountInfo $info)
{
$path = $this->getPath($info->name);
if ($isOverwrite = is_file($path)) {
if (!$this->overwrite) {
return;
}
}
file_put_contents($path, zlib_encode($info->serialize(), ZLIB_ENCODING_DEFLATE));
if (!$isOverwrite and $info->registerTime !== -1) {
$stmt = $this->sql->prepare("INSERT OR REPLACE INTO reg (ip, name, time) VALUES (:ip, :name, :time)");
$stmt->bindValue(":ip", $info->lastIp, SQLITE3_TEXT);
$stmt->bindValue(":name", strtolower($info->name), SQLITE3_TEXT);
$stmt->bindValue(":time", $info->registerTime, SQLITE3_INTEGER);
$stmt->execute();
}
}
开发者ID:PEMapModder,项目名称:HereAuth,代码行数:17,代码来源:JSONAccountWriter.php
示例9: onRun
public function onRun()
{
if (is_file($this->newPath)) {
$this->success = Database::RENAME_TARGET_PRESENT;
return;
}
if (!is_file($this->oldPath)) {
$this->setResult("File didn't exist", false);
$this->success = Database::RENAME_SOURCE_ABSENT;
return;
}
if (!is_dir($dir = dirname($this->newPath))) {
mkdir($dir);
}
$data = json_decode(zlib_decode(file_get_contents($this->oldPath)));
$data->multiHash = ["renamed;{$this->oldName}" => $data->passwordHash];
$data->passwordHash = "{RENAMED}";
unlink($this->oldPath);
file_put_contents($this->newPath, zlib_encode(json_encode($data), ZLIB_ENCODING_DEFLATE));
$this->success = Database::SUCCESS;
}
开发者ID:PEMapModder,项目名称:HereAuth,代码行数:21,代码来源:JsonRenameTask.php
示例10: batchPackets
/**
* Broadcasts a list of packets in a batch to a list of players
*
* @param Player[] $players
* @param DataPacket[]|string $packets
* @param bool $forceSync
*/
public function batchPackets(array $players, array $packets, $forceSync = false)
{
$str = "";
foreach ($packets as $p) {
if ($p instanceof DataPacket) {
if (!$p->isEncoded) {
$p->encode();
}
$str .= $p->buffer;
} else {
$str .= $p;
}
}
$targets = [];
foreach ($players as $p) {
$targets[] = $this->identifiers[\spl_object_hash($p)];
}
if (!$forceSync and $this->networkCompressionAsync) {
$task = new CompressBatchedTask($str, $targets, $this->networkCompressionLevel);
$this->getScheduler()->scheduleAsyncTask($task);
} else {
$this->broadcastPacketsCallback(\zlib_encode($str, ZLIB_ENCODING_DEFLATE, $this->networkCompressionLevel), $targets);
}
}
开发者ID:ZenaGamingsky,项目名称:Steadfast2,代码行数:31,代码来源:Server.php
示例11: inflate_add
$inflated = null;
}
} else {
$inflated = inflate_add($resource, $buffer, ZLIB_FINISH);
}
}
}
$modes = ['ZLIB_ENCODING_RAW' => ZLIB_ENCODING_RAW, 'ZLIB_ENCODING_GZIP' => ZLIB_ENCODING_GZIP, 'ZLIB_ENCODING_DEFLATE' => ZLIB_ENCODING_DEFLATE];
$flushSizes = [1, 4, 32768];
$flushTypes = ['ZLIB_SYNC_FLUSH' => ZLIB_SYNC_FLUSH, 'ZLIB_PARTIAL_FLUSH' => ZLIB_PARTIAL_FLUSH, 'ZLIB_FULL_FLUSH' => ZLIB_FULL_FLUSH, 'ZLIB_NO_FLUSH' => ZLIB_NO_FLUSH, 'ZLIB_BLOCK' => ZLIB_BLOCK];
$uncompressed = "";
for ($i = 0; $i < 32768 * 2; $i++) {
$uncompressed .= chr(rand(48, 125));
}
foreach ($modes as $modeKey => $mode) {
$compressed = zlib_encode($uncompressed, $mode);
$compressedLen = strlen($compressed);
foreach ($flushSizes as $flushSize) {
foreach ($flushTypes as $flushTypeKey => $flushType) {
$inflated = "";
$stream = inflateStream($mode, $flushSize, $flushType);
for ($i = 0; $i < $compressedLen; $i++) {
$inflated .= $stream->send($compressed[$i]);
}
$inflated .= $stream->send(null);
if ($inflated !== $uncompressed) {
echo "Error: {$modeKey} | {$flushSize} | {$flushTypeKey}\n";
}
}
}
}
开发者ID:gleamingthecube,项目名称:php,代码行数:31,代码来源:ext_zlib_tests_inflate_add_basic.php
示例12: compressPacket
private function compressPacket($packet)
{
$packet = $this->uncompressedOut . $packet;
if ($packet == "") {
return "";
}
$len = strlen($packet);
while ($len < self::MAX_UNCOMPRESSED_BUFLEN && !empty($this->out)) {
$packet .= $this->compilePacket();
$len = strlen($this->uncompressedOut);
}
$this->uncompressedOut = substr($packet, self::MAX_UNCOMPRESSED_BUFLEN);
$packet = substr($packet, 0, self::MAX_UNCOMPRESSED_BUFLEN);
$len = strlen($packet);
$deflated = zlib_encode($packet, ZLIB_ENCODING_DEFLATE);
if ($len < strlen($deflated)) {
$out = substr_replace(pack("V", strlen($packet)), chr(++$this->compressionId), 3, 1) . "" . $packet;
} else {
$out = substr_replace(pack("V", strlen($deflated)), chr(++$this->compressionId), 3, 1) . substr(pack("V", $len), 0, 3) . $deflated;
}
return $out;
}
开发者ID:sagara-,项目名称:mysql,代码行数:22,代码来源:Connection.php
示例13: doSlowCleanUp
public function doSlowCleanUp()
{
for ($i = 0; $i < 1024; ++$i) {
if ($this->locationTable[$i][0] === 0 or $this->locationTable[$i][1] === 0) {
continue;
}
fseek($this->filePointer, $this->locationTable[$i][0] << 12);
$chunk = fread($this->filePointer, $this->locationTable[$i][1] << 12);
$length = Binary::readInt(substr($chunk, 0, 4));
if ($length <= 1) {
$this->locationTable[$i] = [0, 0, 0];
//Non-generated chunk, remove it from index
}
try {
$chunk = zlib_decode(substr($chunk, 5));
} catch (\Throwable $e) {
$this->locationTable[$i] = [0, 0, 0];
//Corrupted chunk, remove it
continue;
}
$chunk = chr(self::COMPRESSION_ZLIB) . zlib_encode($chunk, ZLIB_ENCODING_DEFLATE, 9);
$chunk = Binary::writeInt(strlen($chunk)) . $chunk;
$sectors = (int) ceil(strlen($chunk) / 4096);
if ($sectors > $this->locationTable[$i][1]) {
$this->locationTable[$i][0] = $this->lastSector + 1;
$this->lastSector += $sectors;
}
fseek($this->filePointer, $this->locationTable[$i][0] << 12);
fwrite($this->filePointer, str_pad($chunk, $sectors << 12, "", STR_PAD_RIGHT));
}
$this->writeLocationTable();
$n = $this->cleanGarbage();
$this->writeLocationTable();
return $n;
}
开发者ID:Creeperface01,项目名称:ImagicalMine,代码行数:35,代码来源:RegionLoader.php
示例14: getChunkCacheFromData
/**
* @param $chunkX
* @param $chunkZ
* @param $payload
*
* @return DataPacket
*/
public static function getChunkCacheFromData($chunkX, $chunkZ, $payload, $ordering = FullChunkDataPacket::ORDER_COLUMNS)
{
$pk = new FullChunkDataPacket();
$pk->chunkX = $chunkX;
$pk->chunkZ = $chunkZ;
$pk->order = $ordering;
$pk->data = $payload;
$pk->encode();
$batch = new BatchPacket();
$batch->payload = zlib_encode(Binary::writeInt(strlen($pk->getBuffer())) . $pk->getBuffer(), ZLIB_ENCODING_DEFLATE, Server::getInstance()->networkCompressionLevel);
$batch->encode();
$batch->isEncoded = true;
return $batch;
}
开发者ID:NewDelion,项目名称:PocketMine-0.13.x,代码行数:21,代码来源:Player.php
示例15: saveChunkToDisk
public function saveChunkToDisk($x, $z, $payload, $ordering = FullChunkDataPacket::ORDER_COLUMNS)
{
// When the payload of the chunk has been calculated it, save it if possible to save future CPU cycles
/** @var Player $player */
if (file_exists("chunk_cache/" . $this->getName() . "/" . $x . "_" . $z . ".dat")) {
$this->loadChunkFromDisk($x, $z);
return true;
}
$pk = new FullChunkDataPacket();
$pk->chunkX = $x;
$pk->chunkZ = $z;
$pk->order = $ordering;
$pk->data = $payload;
$pk->encode();
// all chunks are zlib_encoded, level is arbitrary but 6 is a good match between device CPU power needed
// and bandwidth
$data = zlib_encode(Binary::writeInt(strlen($pk->buffer)) . $pk->buffer, ZLIB_ENCODING_DEFLATE, 6);
$this->chunkCache[$x . ":" . $z] = $data;
if (!$this->server->getKatana()->getProperty("cache.save-to-disk", true)) {
return true;
}
file_put_contents("chunk_cache/" . $this->getName() . "/" . $x . "_" . $z . ".dat", $data);
return true;
}
开发者ID:AbelGamerC,项目名称:Katana,代码行数:24,代码来源:Level.php
示例16: writeCompressed
public function writeCompressed($compression = ZLIB_ENCODING_GZIP, $level = 7)
{
if (($write = $this->write()) !== false) {
return zlib_encode($write, $compression, $level);
}
return false;
}
开发者ID:ianju,项目名称:PocketMine-MP,代码行数:7,代码来源:NBT.php
示例17: batchPackets
/**
* Broadcasts a list of packets in a batch to a list of players
*
* @param Player[] $players
* @param DataPacket[]|string $packets
* @param bool $forceSync
* @param int $channel
*/
public function batchPackets(array $players, array $packets, $forceSync = false, $channel = 0)
{
Timings::$playerNetworkTimer->startTiming();
$str = "";
foreach ($packets as $p) {
if ($p instanceof DataPacket) {
if (!$p->isEncoded) {
$p->encode();
}
$str .= Binary::writeInt(strlen($p->buffer)) . $p->buffer;
} else {
$str .= Binary::writeInt(strlen($p)) . $p;
}
}
$targets = [];
foreach ($players as $p) {
if ($p->isConnected()) {
$targets[] = $this->identifiers[spl_object_hash($p)];
}
}
if (!$forceSync and $this->networkCompressionAsync) {
$task = new CompressBatchedTask($str, $targets, $this->networkCompressionLevel, $channel);
$this->getScheduler()->scheduleAsyncTask($task);
} else {
$this->broadcastPacketsCallback(zlib_encode($str, ZLIB_ENCODING_DEFLATE, $this->networkCompressionLevel), $targets, $channel);
}
Timings::$playerNetworkTimer->stopTiming();
}
开发者ID:ZenaGamingsky,项目名称:PocketBox,代码行数:36,代码来源:Server.php
示例18: batchDataPacket
/**
* Batch a Data packet
*
* @param DataPacket $packet
*
* @return bool
*/
public function batchDataPacket(DataPacket $packet)
{
$str = "";
if ($packet instanceof DataPacket) {
if (!$packet->isEncoded) {
$packet->encode();
}
$str .= Binary::writeInt(strlen($packet->buffer)) . $packet->buffer;
} else {
$str .= Binary::writeInt(strlen($packet)) . $packet;
}
$pk = new BatchPacket();
$pk->payload = zlib_encode($str, ZLIB_ENCODING_DEFLATE, 7);
$pk->encode();
$pk->isEncoded = true;
$this->dataPacket($pk);
}
开发者ID:WonderlandPE,项目名称:Steadfast2,代码行数:24,代码来源:Player.php
示例19: requestChunkTask
public function requestChunkTask($x, $z)
{
$chunk = $this->getChunk($x, $z, false);
if (!$chunk instanceof Chunk) {
throw new ChunkException("Invalid Chunk sent");
}
$tiles = "";
$nbt = new NBT(NBT::LITTLE_ENDIAN);
foreach ($chunk->getTiles() as $tile) {
if ($tile instanceof Spawnable) {
$nbt->setData($tile->getSpawnCompound());
$tiles .= $nbt->write();
}
}
$extraData = new BinaryStream();
$extraData->putLInt(count($chunk->getBlockExtraDataArray()));
foreach ($chunk->getBlockExtraDataArray() as $key => $value) {
$extraData->putLInt($key);
$extraData->putLShort($value);
}
$ordered = $chunk->getBlockIdArray() . $chunk->getBlockDataArray() . $chunk->getBlockSkyLightArray() . $chunk->getBlockLightArray() . pack("C*", ...$chunk->getHeightMapArray()) . pack("N*", ...$chunk->getBiomeColorArray()) . $extraData->getBuffer() . $tiles;
$pk = new FullChunkDataPacket();
$pk->chunkX = $x;
$pk->chunkZ = $z;
$pk->order = FullChunkDataPacket::ORDER_COLUMNS;
$pk->data = $ordered;
$pk->encode();
$str = "";
$str .= Binary::writeInt(strlen($pk->buffer)) . $pk->buffer;
$this->getLevel()->chunkRequestCallback($x, $z, zlib_encode($str, ZLIB_ENCODING_DEFLATE, 7));
return null;
}
开发者ID:TylerAndrew,项目名称:Steadfast2,代码行数:32,代码来源:McRegion.php
示例20: getChunkCacheFromData
/**
* @param $chunkX
* @param $chunkZ
* @param $payload
*
* @return DataPacket
*/
public static function getChunkCacheFromData($chunkX, $chunkZ, $payload)
{
$pk = new FullChunkDataPacket();
$pk->chunkX = $chunkX;
$pk->chunkZ = $chunkZ;
$pk->data = $payload;
$pk->encode();
$batch = new BatchPacket();
$batch->payload = zlib_encode($pk->getBuffer(), ZLIB_ENCODING_DEFLATE, Server::getInstance()->networkCompressionLevel);
$batch->setChannel(Network::CHANNEL_WORLD_CHUNKS);
$batch->encode();
$batch->isEncoded = true;
return $batch;
}
开发者ID:richarrj,项目名称:PocketMine-MP,代码行数:21,代码来源:Player.php
注:本文中的zlib_encode函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论