当前位置: 首页>>代码示例>>PHP>>正文


PHP lzf_compress函数代码示例

本文整理汇总了PHP中lzf_compress函数的典型用法代码示例。如果您正苦于以下问题:PHP lzf_compress函数的具体用法?PHP lzf_compress怎么用?PHP lzf_compress使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了lzf_compress函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: compress

 /**
  * Compress the given value to the specific compression
  *
  * @param String $sValue
  * @param String $iLevel (Optionnal) : Between 0 and 9
  *
  * @return String
  *
  * @throws Exception
  */
 public function compress($sValue, $iLevel = null)
 {
     if (!is_string($sValue)) {
         throw new Exception('Invalid first argument, must be a string');
     }
     return lzf_compress($sValue);
 }
开发者ID:joostina,项目名称:joostina,代码行数:17,代码来源:LzfCompression.php

示例2: setUp

 public function setUp()
 {
     /** @var SocketInterface $socket */
     $socket = $this->getMock('JLaso\\TradukojConnector\\Socket\\SocketInterface');
     $socket->method('write')->will($this->returnCallback(function ($msg, $len) {
         return $len;
     }));
     $socket->method('read')->will($this->returnCallback(function ($len, $type) {
         switch ($len) {
             case 10:
                 return ClientSocketApi::ACK . PHP_EOL;
             case 2048:
                 return "Welcome!";
             default:
                 $val = '{"result":false,"reason":"test"}' . PHP_EOL;
                 $val = function_exists('lzf_compress') ? lzf_compress($val) : gzcompress($val);
                 return sprintf("%06d:001:001:%s", strlen($val), $val);
         }
     }));
     $loader = new ArrayLoader();
     $config = $loader->load($this->getConfigArray());
     $postClient = $this->getMock('JLaso\\TradukojConnector\\PostClient\\PostClientInterface');
     $postClient->method('call')->will($this->returnCallback(function ($url, $data) {
         return ClientSocketApiTest::postClientCallMock($url, $data);
     }));
     $nullOutput = new NullOutput();
     $this->clientSocketApi = new ClientSocketApi($config, $socket, $postClient, $nullOutput);
 }
开发者ID:jlaso,项目名称:tradukoj-connector,代码行数:28,代码来源:ClientSocketApiTest.php

示例3: compress

 public function compress($data = '', $blockSize = NULL, $workFactor = NULL)
 {
     if (!is_scalar($data)) {
         return Error::set('Error', 'valueParameter', '1.(data)');
     }
     return lzf_compress($data);
 }
开发者ID:bytemtek,项目名称:znframework,代码行数:7,代码来源:LZF.php

示例4: compress

 public function compress($data = '')
 {
     if (!isValue($data)) {
         return Error::set(lang('Error', 'valueParameter', '1.(data)'));
     }
     return lzf_compress($data);
 }
开发者ID:Allopa,项目名称:ZN-Framework-Starter,代码行数:7,代码来源:LZFDriver.php

示例5: sendMessage

 protected function sendMessage($msg, $compress = true)
 {
     if ($compress) {
         if (function_exists(self::LZF_FUNCTION)) {
             $msg = lzf_compress($msg);
         } else {
             $msg = gzcompress($msg, 9);
         }
     } else {
         $msg .= PHP_EOL;
     }
     $len = strlen($msg);
     if (self::DEBUG) {
         print "sending {$len} chars" . PHP_EOL;
     }
     $blocks = ceil($len / self::BLOCK_SIZE);
     for ($i = 0; $i < $blocks; $i++) {
         $block = substr($msg, $i * self::BLOCK_SIZE, $i == $blocks - 1 ? $len - ($i - 1) * self::BLOCK_SIZE : self::BLOCK_SIZE);
         $prefix = sprintf("%06d:%03d:%03d:", strlen($block), $i + 1, $blocks);
         $aux = $prefix . $block;
         if (self::DEBUG) {
             print sprintf("sending block %d from %d, prefix = %s\n", $i + 1, $blocks, $prefix);
         }
         if (false === socket_write($this->socket, $aux, strlen($aux))) {
             die('error');
         }
         do {
             $read = socket_read($this->socket, 10, PHP_NORMAL_READ);
             //print $read;
         } while (strpos($read, self::ACK) !== 0);
     }
     return true;
 }
开发者ID:jlaso,项目名称:tradukoj-po-mo-module,代码行数:33,代码来源:ClientSocketService.php

示例6: compress

 /**
  * Compresses the given content
  *
  * @param  string $content
  * @return string
  */
 public function compress($content)
 {
     $compressed = lzf_compress($content);
     if (!$compressed) {
         throw new Zend_Filter_Exception('Error during compression');
     }
     return $compressed;
 }
开发者ID:kobmaki,项目名称:icingaweb2,代码行数:14,代码来源:Lzf.php

示例7: compress

 /**
  * Compresses the given content
  *
  * @param  string $content
  * @return string
  * @throws Exception\RuntimeException if error occurs during compression
  */
 public function compress($content)
 {
     $compressed = lzf_compress($content);
     if (!$compressed) {
         throw new Exception\RuntimeException('Error during compression');
     }
     return $compressed;
 }
开发者ID:eltondias,项目名称:Relogio,代码行数:15,代码来源:Lzf.php

示例8: compress

 /**
  * Compresses the given content
  *
  * @param  string $content
  * @return string
  */
 public function compress($content)
 {
     $compressed = lzf_compress($content);
     if (!$compressed) {
         require_once 'Zend/Filter/Exception.php';
         throw new Zend_Filter_Exception('Error during compression');
     }
     return $compressed;
 }
开发者ID:Yaoming9,项目名称:Projet-Web-PhP,代码行数:15,代码来源:Lzf.php

示例9: compress

 /**
  * Compresses the given content
  *
  * @param  string $content
  * @return string
  */
 public function compress($content)
 {
     $compressed = lzf_compress($content);
     if (!$compressed) {
         require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/Filter/Exception.php';
         throw new IfwPsn_Vendor_Zend_Filter_Exception('Error during compression');
     }
     return $compressed;
 }
开发者ID:jasmun,项目名称:Noco100,代码行数:15,代码来源:Lzf.php

示例10: testLzfDriverDecompress

 public function testLzfDriverDecompress()
 {
     try {
         $ob = new Horde_Compress_Fast(array('drivers' => array('Horde_Compress_Fast_Lzf')));
     } catch (Horde_Compress_Fast_Exception $e) {
         $this->markTestSkipped('LZF extension not available.');
     }
     $this->assertEquals($this->compress_text, $ob->decompress(lzf_compress($this->compress_text)));
     try {
         $ob->decompress(new stdClass());
         $this->fail('Expected exception.');
     } catch (Horde_Compress_Fast_Exception $e) {
     }
 }
开发者ID:jubinpatel,项目名称:horde,代码行数:14,代码来源:CompressFastTest.php

示例11: set

 /**
  * Set cached data.
  *
  * @param string $key  Cache key.
  * @param mixed $data  Data to store.
  *
  * @return boolean  True on success, false on failure.
  */
 public function set($key, $data)
 {
     $data = $this->_mask & self::MSGPACK ? msgpack_pack($data) : json_encode($data);
     if ($this->_mask & self::LZ4) {
         $data = @horde_lz4_compress($data);
     } elseif ($this->_mask & self::LZF) {
         $data = lzf_compress($data);
     }
     if ($this->_mask & self::APC) {
         return apc_store($key, $data);
     } elseif ($this->_mask & self::XCACHE) {
         return xcache_set($key, $data);
     } elseif ($this->_mask & self::EACCELERATOR) {
         eaccelerator_put($key, $data);
         return true;
     } elseif ($this->_mask & self::TEMPFILE) {
         return file_put_contents($this->_tempdir . '/' . $key, $data);
     }
     return false;
 }
开发者ID:jubinpatel,项目名称:horde,代码行数:28,代码来源:Bootstrap.php

示例12: _encodeData

 /**
  * @param string $data
  * @param int $level
  * @throws Exception
  * @return string
  */
 protected function _encodeData($data, $level)
 {
     if ($level && strlen($data) >= $this->_compressThreshold) {
         switch ($this->_compressionLib) {
             case 'snappy':
                 $data = snappy_compress($data);
                 break;
             case 'lzf':
                 $data = lzf_compress($data);
                 break;
             case 'gzip':
                 $data = gzcompress($data, $level);
                 break;
         }
         if (!$data) {
             throw new Exception("Could not compress cache data.");
         }
         return $this->_compressPrefix . $data;
     }
     return $data;
 }
开发者ID:RabeaWahab,项目名称:Rabee3_Cache_Backend_RedisCluster,代码行数:27,代码来源:RedisCluster.php

示例13: _serialize

 /**
  * Serialize data.
  *
  * @param mixed $data    The data to be serialized.
  * @param mixed $mode    The mode of serialization. Can be
  *                       either a single mode or array of modes.
  *                       If array, will be serialized in the
  *                       order provided.
  * @param mixed $params  Any additional parameters the serialization method
  *                       requires.
  *
  * @return string  A serialized string.
  * @throws Horde_Serialize_Exception
  */
 protected static function _serialize($data, $mode, $params = null)
 {
     switch ($mode) {
         case self::NONE:
             break;
             // $params['level'] = Level of compression (default: 3)
             // $params['workfactor'] = How does compression phase behave when given
             //                         worst case, highly repetitive, input data
             //                         (default: 30)
         // $params['level'] = Level of compression (default: 3)
         // $params['workfactor'] = How does compression phase behave when given
         //                         worst case, highly repetitive, input data
         //                         (default: 30)
         case self::BZIP:
             $data = bzcompress($data, isset($params['level']) ? $params['level'] : 3, isset($params['workfactor']) ? $params['workfactor'] : 30);
             if (is_integer($data)) {
                 $data = false;
             }
             break;
         case self::WDDX:
             $data = wddx_serialize_value($data);
             break;
         case self::IMAP8:
             $data = Horde_Mime::quotedPrintableEncode($data);
             break;
         case self::IMAPUTF7:
             $data = Horde_Imap_Client_Utf7imap::Utf8ToUtf7Imap(Horde_String::convertCharset($data, 'ISO-8859-1', 'UTF-8'));
             break;
         case self::IMAPUTF8:
             $data = Horde_Mime::decode($data);
             break;
             // $params['level'] = Level of compression (default: 3)
         // $params['level'] = Level of compression (default: 3)
         case self::GZ_DEFLATE:
             $data = gzdeflate($data, isset($params['level']) ? $params['level'] : 3);
             break;
         case self::BASIC:
             $data = serialize($data);
             break;
             // $params['level'] = Level of compression (default: 3)
         // $params['level'] = Level of compression (default: 3)
         case self::GZ_COMPRESS:
             $data = gzcompress($data, isset($params['level']) ? $params['level'] : 3);
             break;
         case self::BASE64:
             $data = base64_encode($data);
             break;
             // $params['level'] = Level of compression (default: 3)
         // $params['level'] = Level of compression (default: 3)
         case self::GZ_ENCODE:
             $data = gzencode($data, isset($params['level']) ? $params['level'] : 3);
             break;
         case self::RAW:
             $data = rawurlencode($data);
             break;
         case self::URL:
             $data = urlencode($data);
             break;
             // $params = Source character set
         // $params = Source character set
         case self::UTF7:
             $data = Horde_String::convertCharset($data, $params, 'UTF-7');
             break;
             // $params = Source character set
         // $params = Source character set
         case self::UTF7_BASIC:
             $data = self::serialize($data, array(self::UTF7, self::BASIC), $params);
             break;
         case self::JSON:
             $tmp = json_encode($data);
             /* Basic error handling attempts.
              * TODO: JSON_ERROR_UTF8 = 5; available as of PHP 5.3.3 */
             if (json_last_error() === 5) {
                 $data = json_encode(Horde_String::convertCharset($data, $params, 'UTF-8', true));
             } else {
                 $data = $tmp;
             }
             break;
         case self::LZF:
             $data = lzf_compress($data);
             break;
     }
     if ($data === false) {
         throw new Horde_Serialize_Exception('Serialization failed.');
     }
     return $data;
//.........这里部分代码省略.........
开发者ID:jubinpatel,项目名称:horde,代码行数:101,代码来源:Serialize.php

示例14: compress

 /**
  * @param string $message
  *
  * @return string
  */
 protected function compress($message)
 {
     return function_exists('lzf_compress') ? lzf_compress($message) : gzcompress($message, 9);
 }
开发者ID:jlaso,项目名称:tradukoj-connector,代码行数:9,代码来源:ClientSocketApi.php

示例15: _encodeData

 /**
  * Public for testing purposes only.
  *
  * @param string $data
  * @return string
  */
 public function _encodeData($data)
 {
     $this->profilerStart(__METHOD__);
     $originalDataSize = strlen($data);
     if ($this->_compressionThreshold > 0 && $this->_compressionLib != 'none' && $originalDataSize >= $this->_compressionThreshold) {
         if ($this->_logLevel >= \Zend_Log::DEBUG) {
             $this->_log(sprintf("Compressing %s bytes with %s", $originalDataSize, $this->_compressionLib));
             $timeStart = microtime(true);
         }
         $prefix = ':' . substr($this->_compressionLib, 0, 2) . ':';
         switch ($this->_compressionLib) {
             case 'snappy':
                 $data = snappy_compress($data);
                 break;
             case 'lzf':
                 $data = lzf_compress($data);
                 break;
             case 'lz4':
                 $data = lz4_compress($data);
                 $prefix = ':l4:';
                 break;
             case 'gzip':
                 $data = gzcompress($data, 1);
                 break;
         }
         if ($data) {
             $data = $prefix . $data;
             if ($this->_logLevel >= \Zend_Log::DEBUG) {
                 $this->_log(sprintf("Data compressed by %.1f percent in %.5f seconds", $originalDataSize == 0 ? 0 : 100 - strlen($data) / $originalDataSize * 100, microtime(true) - $timeStart));
             }
         } else {
             if ($this->_logLevel >= \Zend_Log::WARN) {
                 $this->_log(sprintf("Could not compress session data using %s", $this->_compressionLib), \Zend_Log::WARN);
             }
         }
     }
     $this->profilerStop(__METHOD__);
     return $data;
 }
开发者ID:joanhe,项目名称:Cm_RedisSession,代码行数:45,代码来源:Handler.php


注:本文中的lzf_compress函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。