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


PHP gzcompress函数代码示例

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


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

示例1: Save

 public static function Save($strFormState, $blnBackButtonFlag)
 {
     // Compress (if available)
     if (function_exists('gzcompress')) {
         $strFormState = gzcompress($strFormState, 9);
     }
     // Setup CurrentStateIndex (if none yet exists)
     if (!array_key_exists('qform_current_state_index', $_SESSION)) {
         $_SESSION['qform_current_state_index'] = 0;
     }
     // Increment CurrentStateIndex if BackButtonFlag is true
     // Otherwise, we're in an ajax-to-ajax call, and the back button is invalid anyway
     // No need to increment session state index -- let's not to save space
     //			if ($blnBackButtonFlag)
     $_SESSION['qform_current_state_index'] = $_SESSION['qform_current_state_index'] + 1;
     $intStateIndex = $_SESSION['qform_current_state_index'];
     // Save THIS formstate
     // NOTE: if gzcompress is used, we are saving the *BINARY* data stream of the compressed formstate
     // In theory, this SHOULD work.  But if there is a webserver/os/php version that doesn't like
     // binary session streams, you can first base64_encode before saving to session (see note below).
     $_SESSION['qform_' . $intStateIndex] = $strFormState;
     // Return StateIndex
     if (!is_null(QForm::$EncryptionKey)) {
         // Use QCryptography to Encrypt
         $objCrypto = new QCryptography(QForm::$EncryptionKey, true);
         return $objCrypto->Encrypt($intStateIndex);
     } else {
         return $intStateIndex;
     }
 }
开发者ID:alcf,项目名称:chms,代码行数:30,代码来源:QSessionFormStateHandler.class.php

示例2: compress

function compress($data, $compressed)
{
    if ($compressed == 1) {
        return gzcompress($data);
    }
    return $data;
}
开发者ID:ber5ien,项目名称:www.jade-palace.co.uk,代码行数:7,代码来源:common.functions.php

示例3: wirte

 /**
  * 写入缓存
  * @param string $name 缓存文件名字
  * @param function $callback 回调函数,必须要有返回值
  * @param Array or string or Object $params 要传进去的参数
  * @param int $time 写入的缓存时间
  * @return array
  * @author wave
  */
 public static function wirte($name, $callback, $params = null, $time = TIME)
 {
     self::init();
     $file = ROOT . DS . APP_PATH . DS . self::$cache_dir;
     $content = '';
     if (!file_exists($file . self::CACHE_PREFIX . $name)) {
         $content = $callback($params);
         if (!empty($content)) {
             file_put_contents($file . self::CACHE_PREFIX . $name, gzcompress(serialize($content)));
             return;
         }
     }
     if (empty($time)) {
         return;
     }
     if (file_exists($file . self::CACHE_PREFIX . $name)) {
         $cache_time = strtotime(date('Y-m-d H:i:s')) - strtotime(date('Y-m-d H:i:s', filemtime($file . self::CACHE_PREFIX . $name)));
         if ($cache_time / 1000 >= $time || $time == 1) {
             $content = $callback($params);
             if (!empty($content)) {
                 file_put_contents($file . self::CACHE_PREFIX . $name, gzcompress(serialize($content)));
                 return;
             }
         }
     }
 }
开发者ID:DenonHuang,项目名称:xbphp,代码行数:35,代码来源:Cache.php

示例4: set

 /**
  * 写入缓存
  * @access public
  * @param string $name 缓存变量名
  * @param mixed $value  存储数据
  * @param int $expire  有效时间 0为永久
  * @return boolean
  */
 public function set($name, $value, $expire = null)
 {
     if (is_null($expire)) {
         $expire = $this->options['expire'];
     }
     $filename = $this->getFileName($name);
     $data = serialize($value);
     //是否数据压缩
     if ($this->options['compress'] && function_exists('gzcompress')) {
         //数据压缩
         $data = gzcompress($data, 3);
     }
     //是否数据校验
     if ($this->options['check']) {
         $check = md5($data);
     } else {
         $check = '';
     }
     $data = "<?php\n//" . sprintf('%012d', $expire) . $check . $data . "\n?>";
     $result = file_put_contents($filename, $data);
     if ($result) {
         //            if($this->options['length']>0) {
         //                // 记录缓存队列
         //                $this->queue($name);
         //            }
         clearstatcache();
         return true;
     } else {
         return false;
     }
 }
开发者ID:huangbinzd,项目名称:yaf_private_test,代码行数:39,代码来源:File.php

示例5: save_array_dump

function save_array_dump($filename, $array)
{
    $dump = addslashes(gzcompress(var_export($array, true), 9));
    $fp = fopen($filename, "wb+");
    fwrite($fp, $dump);
    fclose($fp);
}
开发者ID:ItsLines,项目名称:ThePreviouslyDesigned,代码行数:7,代码来源:helper_lib.php

示例6: secure_serialize

 function secure_serialize($data)
 {
     $mainframe =& JFactory::getApplication();
     $secret = $mainframe->getCfg('secret');
     $sData = strtr(base64_encode(addslashes(gzcompress(serialize($data), 9))), '+/=', '-_,');
     return sha1($sData . $secret) . $sData;
 }
开发者ID:acculitx,项目名称:fleetmatrixsite,代码行数:7,代码来源:cfaction_load_js.php

示例7: print_gzipped_page

 function print_gzipped_page()
 {
     $HTTP_ACCEPT_ENCODING = getenv("HTTP_ACCEPT_ENCODING");
     if (headers_sent()) {
         $encoding = false;
     } elseif (strpos($HTTP_ACCEPT_ENCODING, 'x-gzip') !== false) {
         $encoding = 'x-gzip';
     } elseif (strpos($HTTP_ACCEPT_ENCODING, 'gzip') !== false) {
         $encoding = 'gzip';
     } else {
         $encoding = false;
     }
     if ($encoding) {
         $contents = ob_get_contents();
         ob_end_clean();
         header('Content-Encoding: ' . $encoding);
         header("ETag: " . md5($contents));
         // ETag im Header senden
         header("Expires: " . date("r", mktime(0, 0, 0, date("n"), date("j") + 365)));
         print "�";
         $size = strlen($contents);
         $contents = gzcompress($contents, 9);
         $contents = substr($contents, 0, $size);
         print $contents;
         //             exit();
     } else {
         ob_end_flush();
         //             exit();
     }
 }
开发者ID:BackupTheBerlios,项目名称:ewebuki-bvv-svn,代码行数:30,代码来源:gzip_files.php

示例8: exec

 /**
  * Sends a command to the server and returns an object with the result 
  * 
  * @param string $cmd               Protocol command to be executed
  * @param string $message           Full email message
  * @param array  $additionalHeaders Associative array with additional headers
  */
 protected function exec($cmd, $message, array $additionalHeaders = array())
 {
     $socket = $this->getSocket();
     $message .= "\r\n";
     $contentLength = strlen($message);
     if (!empty($this->maxSize)) {
         if ($contentLength > $this->maxSize) {
             throw new Exception("Message exceeds the maximum allowed size of {$this->maxSize} kbytes");
         }
     }
     $cmd = $cmd . ' SPAMC/' . $this->protocolVersion . "\r\n";
     $cmd .= "Content-length: {$contentLength}\r\n";
     if ($this->enableZlib && function_exists('gzcompress')) {
         $cmd .= "Compress: zlib\r\n";
         $message = gzcompress($message);
     }
     if (!empty($this->user)) {
         $cmd .= 'User: ' . $this->user . "\r\n";
     }
     if (!empty($additionalHeaders)) {
         foreach ($additionalHeaders as $headerName => $val) {
             $cmd .= $headerName . ': ' . $val . "\r\n";
         }
     }
     $cmd .= "\r\n";
     $cmd .= $message;
     $cmd .= "\r\n";
     $this->write($socket, $cmd);
     list($headers, $message) = $this->read($socket);
     return $this->parseOutput($headers, $message);
 }
开发者ID:sumudinie,项目名称:hubzero-cms,代码行数:38,代码来源:Local.php

示例9: compile

 function compile($compressionLevel = 0)
 {
     $this->header->setCompressed($compressionLevel > 0);
     $data = '';
     foreach ($this->tags as $tag) {
         $data .= $tag->getTagContent();
     }
     $header = $this->header->getPacked();
     $len = strlen($header) + strlen($data);
     $this->header->filelength->set($len);
     $data = $this->header->getPacked() . $data;
     if ($compressionLevel > 0) {
         $compressionStartTime = $this->microtime_float();
         // The first eight bytes are uncompressed
         $uncompressedBytes = substr($data, 0, 8);
         // Remove first eight bytes
         $data = substr_replace($data, '', 0, 8);
         // Compress the rest of the SWF
         $data = gzcompress($data, $compressionLevel);
         // Add the uncompressed header
         $data = $uncompressedBytes . $data;
         $compressionDuration = $this->microtime_float() - $compressionStartTime;
         if (LOG_ALL) {
             error_log('[SWX] PROFILING: SWF compression took ' . $compressionDuration . ' seconds.');
         }
         // Stats
         $compressedSize = strlen($data);
         if (LOG_ALL) {
             error_log('[SWX] INFO Compressed size of SWF: ' . $compressedSize . ' bytes.');
         }
     }
     $this->data = $data;
 }
开发者ID:hafizubikm,项目名称:bakeme,代码行数:33,代码来源:SwxAssembler3.php

示例10: append

 /**
  * Forwards the logging event to the Graylog2 server.
  * @param LoggerLoggingEvent $event
  */
 protected function append(LoggerLoggingEvent $event)
 {
     $message = gzcompress($this->layout->format($event));
     $socket = $this->getSocketConnection();
     if (strlen($message) > $this->getChunkSize()) {
         // A unique id which consists of the microtime and a random value
         $messageId = uniqid();
         // Split the message into chunks
         $messageChunks = str_split($message, $this->getChunkSize());
         $messageChunksCount = count($messageChunks);
         // Send chunks to graylog server
         foreach ($messageChunks as $messageChunkIndex => $messageChunk) {
             $bytesWritten = $this->writeMessageChunkToSocket($socket, $messageId, $messageChunk, $messageChunkIndex, $messageChunksCount);
             if (false === $bytesWritten) {
                 // Abort due to write error
                 return false;
             }
         }
     } else {
         // A single write is enough to get the message published
         if (false === $this->writeMessageToSocket($socket, $message)) {
             // Abort due to write error
             return false;
         }
     }
 }
开发者ID:rurri,项目名称:log4php-graylog2,代码行数:30,代码来源:LoggerAppenderGraylog2.php

示例11: set

 public function set($key, $value, $expire = '')
 {
     $freeSpace = disk_free_space($this->config['path']);
     $freeSpaceMB = $freeSpace ? floor($freeSpace / 1024 / 1024) : 0;
     if ($freeSpaceMB < 10) {
         Axion_log::getinstance()->newMessage('磁盘容量过小,无法存储数据缓存文件', AXION_LOG::WARNING);
         return false;
     }
     $hash = md5($key);
     $expire = $expire ? $expire : $this->config['expire'];
     $expire = sprintf('%09d', $expire);
     $data = serialize($value);
     self::$_data[$hash] = $data;
     if (!is_dir($this->config['path'])) {
         if (!AXION_UTIL_FILE::mkdir($this->config['path'])) {
             throw new AXION_EXCEPTION('无法创建Cache文件目录:' . $this->config['path']);
         }
     }
     $fileName = $this->genFileName($key);
     if (IS_SHM && function_exists('gzcompress')) {
         $data = gzcompress($data, 4);
     }
     $data = $expire . $data;
     $result = file_put_contents($fileName, $data);
     if ($result) {
         clearstatcache();
         return true;
     } else {
         return false;
     }
 }
开发者ID:kellenqian,项目名称:axion,代码行数:31,代码来源:file.class.php

示例12: save

 public static function save($label, $data, $expires = null, $compress = true)
 {
     $label = urlencode($label);
     $dir = rtrim(self::$dir, "/");
     if (is_object($data) || is_array($data)) {
         if (method_exists($data, "__toString")) {
             $data = call_user_func(array($data, '__toString'));
         } else {
             $data = serialize($data);
         }
     }
     $str = (string) gzcompress($data);
     if (strlen($str) > $data) {
         $str = $data;
     }
     if ((bool) file_put_contents("{$dir}/{$label}", $str)) {
         if ($expires) {
             $expires = time() + (int) $expires;
         } else {
             $expires = time() + 60 * 60 * 24 * 365 * 10;
         }
         touch("{$dir}/{$label}", time(), $expires);
         return $data;
     } else {
         throw new Exception("Could not cache file.", 0);
     }
 }
开发者ID:alexbrombal,项目名称:saffyre-junk,代码行数:27,代码来源:Cache.php

示例13: encode

 protected function encode($value = null)
 {
     if (!$value) {
         return '';
     }
     return base64_encode(gzcompress(serialize($value)));
 }
开发者ID:ahyswang,项目名称:eva-engine,代码行数:7,代码来源:Cookie.php

示例14: ncd_new

function ncd_new($sx, $sy, $prec = 0, $MAXLEN = 9000)
{
    # NCD with gzip artifact correctoin and percentual return.
    # sx,sy = strings to compare.
    # Use $prec=-1 for result range [0-1], $pres=0 for percentual,
    # For NCD definition see http://arxiv.org/abs/0809.2553
    $x = $min = strlen(gzcompress($sx));
    $y = $max = strlen(gzcompress($sy));
    $xy = strlen(gzcompress($sx . $sy));
    $a = $sx;
    if ($x > $y) {
        # swap min/max
        $min = $y;
        $max = $x;
        $a = $sy;
    }
    $res = ($xy - $min) / $max;
    # NCD definition.
    #Little strings):
    if ($MAXLEN < 0 || $xy < $MAXLEN) {
        $aa = strlen(gzcompress($a . $a));
        $ref = ($aa - $min) / $min;
        $res = $res - $ref;
        # correction
    }
    return $prec < 0 ? $res : 100 * round($res, 2 + $prec);
}
开发者ID:zahidhameed,项目名称:Plagiarism-Detection-Tool,代码行数:27,代码来源:pattern.php

示例15: serialize

 public static function serialize($data, $type)
 {
     $types = explode('|', $type, 2);
     switch ($types[0]) {
         case self::SERIALIZE_TYPE_BASE64:
             if (!empty($types[1])) {
                 $data = self::serialize($data, $types[1]);
             }
             return self::SERIALIZE_TYPE_BASE64 . ' ' . base64_encode($data);
         case self::SERIALIZE_TYPE_GZIP:
             if (!empty($types[1])) {
                 $data = self::serialize($data, $types[1]);
             }
             if (strlen($data) < self::GZIP_MIN_LENGTH) {
                 return $data;
             }
             return self::SERIALIZE_TYPE_GZIP . ' ' . gzcompress($data);
         case self::SERIALIZE_TYPE_PHP_SERIALIZE:
             return self::SERIALIZE_TYPE_PHP_SERIALIZE . ' ' . serialize($data);
         case self::SERIALIZE_TYPE_JSON:
             return self::SERIALIZE_TYPE_JSON . ' ' . json_encode($data);
         default:
             throw new InvalidArgumentException();
     }
 }
开发者ID:mailru,项目名称:queue-processor,代码行数:25,代码来源:MapperUtils.php


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