header('Content-Type:text/plain'); $s = file_get_contents('http://www.oschina.net/question/998019_121505'); $data = array('data'=>str_repeat($s,100)); function benchmark($function, $times=1){ $started_at = microtime(1); $data = null; for($i=0; $i<$times; $i++){ $data = $function(); printf("%.5fs, length:%.5fm\n\n", microtime(1)-$started_at, (strlen($data) / 1024 /1024)); echo "serialize \n"; benchmark(function() use($data){ $t = ((serialize($data))); $s = unserialize((($t))); return $t; echo "serialize + base64 \n"; benchmark(function() use($data){ $t = base64_encode((serialize($data))); $s = unserialize((base64_decode($t))); return $t; echo "serialize + gzip \n"; benchmark(function() use($data){ $t = (gzcompress(serialize($data))); $s = unserialize(gzuncompress(($t))); return $t; echo "serialize+base64_encode +gzip \n"; benchmark(function() use($data){ $t = base64_encode(gzcompress(serialize($data))); $s = unserialize(gzuncompress(base64_decode($t))); return $t; exit();

运行结果:

serialize 0.01427s, length:6.02410m serialize + base64 0.17287s, length:8.03214m serialize + gzip 0.43907s, length:1.44310m serialize+base64_encode +gzip 0.51364s, length:1.92414m 感觉各有优势, 不知道选择哪种方案来做... 要么时间慢, 要么容量大, 暂没有即时间快,又容量小的方案,权衡下,选择合适的来用。 文章来源于:开源中国社区:http://www.oschina.net/question/998019_121505 <?php@set_time_limit(0);if(php_sapi_name()!=='cli') { header('Content-Type:text/plain');}$s = file_get_contents('http://www.oschina.net/question/998019_121505'); $data = array('data'=>str_re 1. 使用 PHP 扩展的ZipArchive类 2. 使用 压缩 与解 压缩 类PclZip. php 3. 使用 PHP 函数exec()执行Linux下的 压缩 zip,解 压缩 unzip命令 1. 使用 PHP 扩展的ZipArchive类 使用之前要将 php .ini文件中的zlib.output...
网络通信、文件存储中经常需要交换数据,为了减少网络通信流量、文件存储大小以及加密通信规则,经常需要对数据 进行 双向加解密以保证数据的安全。 PHP 中实现此功能主要需要使用的函数主要是pack及unpack函数 压缩 资料到位字符串之中。 语法: string pack(string format, mixed [args]...); 返回值: 字符串 本函数用来将
[原文来自于转载, 但他的结论不太正确, 尤其对foreach的判断这块上, 我拎过来 进行 修理 ] 在做数据统计时,难免会遇到大 数组 ,而处理大数据经常会发生内存溢出,这篇文章中,我们聊聊如何处理大 数组 。 常见的大 数组 大多来自两种情况: 大文件的处理 DB读取大数据的处理 这里重点讲下DB读取大数据的处理,顺便简单介绍下大文件处理,希望对大家有帮助,看完后可以轻松解决各种...
void bubbleSort(int arr[], int n) { for (int i = 0; i < n-1; i++) { for (int j = 0; j < n-i-1; j++) { if (arr[j] > arr[j+1]) { int temp = arr[j]; arr[j] = arr[j+1]; arr[j+1] = temp; 其中,arr[] 表示待排序的 数组 ,n 表示 数组 的长度。