本文整理汇总了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);
}
示例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);
}
示例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);
}
示例4: compress
public function compress($data = '')
{
if (!isValue($data)) {
return Error::set(lang('Error', 'valueParameter', '1.(data)'));
}
return lzf_compress($data);
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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) {
}
}
示例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;
}
示例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;
}
示例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;
//.........这里部分代码省略.........
示例14: compress
/**
* @param string $message
*
* @return string
*/
protected function compress($message)
{
return function_exists('lzf_compress') ? lzf_compress($message) : gzcompress($message, 9);
}
示例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;
}