PHP加速器APC
来源:互联网 发布:mac c语言开发工具 编辑:程序博客网 时间:2024/04/30 00:02
<p style="font-family: 'Microsoft Yahei', 'Helvetica Neue', 'Luxi Sans', 'DejaVu Sans', Tahoma, 'Hiragino Sans GB', STHeiti; font-size: 16px; line-height: 25px;">PHP加速器APC除了缓存字节码,还有一个很重要的应用就是 apc_store, 通常会将配置信息使用apc 缓存起来,更多时候是我们发现配置信息的数组太大了,才考虑将整个数组使用apc缓存起来。</p><p style="font-family: 'Microsoft Yahei', 'Helvetica Neue', 'Luxi Sans', 'DejaVu Sans', Tahoma, 'Hiragino Sans GB', STHeiti; font-size: 16px; line-height: 25px;">下面我们明确一点基本的知识: apc缓存PHP的数组是序列化之后存储的,</p><p style="font-family: 'Microsoft Yahei', 'Helvetica Neue', 'Luxi Sans', 'DejaVu Sans', Tahoma, 'Hiragino Sans GB', STHeiti; font-size: 16px; line-height: 25px;">下面我们做一个测试:测试代码:</p>
<?phptest_exec_code();test_unserialize();test_apc_fetch_arr();test_apc_fetch_str();test_apc_fetch_str_then_unserialize();function test_exec_code() { $s = microtime(1); while($i++<1000) { $arr = getData(); } echo "exec time:", microtime(1) - $s , "s\n";}function test_unserialize() { $arr = getData(); $str = serialize($arr); $s = microtime(1); $i = 0; while($i++<1000) { $arr = unserialize($str); } echo "unserialize time:", microtime(1) - $s , "s\n";}function test_apc_fetch_arr() { $arr = getData(); apc_store("arr", $arr); $s = microtime(1); $i = 0; while($i++<1000) { $arr = apc_fetch("arr"); } echo "apc_fetch_arr time:", microtime(1) - $s , "s\n";}function test_apc_fetch_str() { $arr = getData(); $str = serialize($arr); apc_store("str", $str); $s = microtime(1); $i = 0; while($i++<1000) { $str = apc_fetch("str"); } echo "apc_fetch_str time:", microtime(1) - $s , "s\n";}function test_apc_fetch_str_then_unserialize() { $arr = getData(); $str = serialize($arr); apc_store("str", $str); $s = microtime(1); $i = 0; while($i++<1000) { $str = apc_fetch("str"); $arr = unserialize($str); } echo "apc_fetch_str_then_unserialize time:", microtime(1) - $s , "s\n";}function getData() { $arr = array( '220.181.7.41', '113.5.32.130', //... 共 9000 个IP ); return $arr;}测试结果:$ php test.phpexec time:5.3702118396759sunserialize time:7.4545278549194sapc_fetch_arr time:50.132069826126sapc_fetch_str time:0.18340110778809sapc_fetch_str_then_unserialize time:7.9918370246887s分析:
1. 不做缓存,每次都执行字节码的效率是最高的,大约每次执行需要 5ms 的时间
2. PHP 反序列话的速度也赶不上执行字节码的速度(至少在这种情况下是这样的)
3. 使用apc缓存数组的效率是相当低的, 每次约 50ms,不如不缓存
4. 使用apc缓存字符串的速度还是不错的,这里的数据量约为260KB,fetch一次的时间约0.18ms
5. 如果说apc的序列化和反序列化使用的是php标准的序列化和反序列化函数,则: apc_fetch_arr 的时间应该基本和 apc_fetch_str_then_unserialize time 的时间一样,但是,这里差别太大了,有些不太理解; 如此看来,如果真要使用apc,则最好先显式地序列化然后在存储,fetch后在显式地反序列化一下
http://blogread.cn/it/article/5487?f=wb
0 0
- PHP加速器APC
- PHP加速器APC
- php缓存(加速器) APC 和 eAccelerator
- Linux 编译安装PHP加速器:APC
- PHP加速器:APC、eAccelerator、XCache比较
- centOS5.5 安装 PHP APC缓存加速器
- ubuntu php 加速器 APC安装 整理
- liunx下安装 php加速器APC
- PHP加速器:APC、eAccelerator、XCache比较
- 三款免费的PHP加速器:APC、eAccelerator、XCache比较
- 款免费的PHP加速器:APC、eAccelerator、XCache比较
- 三款免费的PHP加速器:APC、eAccelerator、XCache比较
- 三款PHP加速器:APC/eAccelerator/XCache对比测试
- 三款免费的PHP加速器:APC、eAccelerator、XCache比较
- 三款免费的PHP加速器:APC、eAccelerator、XCache比较
- Linux下编译安装PHP加速器APC [linux]
- 三款免费的PHP加速器:APC、eAccelerator、XCache比较
- Linux下PHP加速器APC的安装与配置
- DirectX 11游戏编程学习笔记之1: 开场白
- VMware的Ubuntu与实际机器之间文本的复制粘贴
- centos下ftp安装及添加账户
- memblkA 最简单的内存模拟块设备 源码
- Sundy嵌入式底层开发课程笔记1 --shell命令机制
- PHP加速器APC
- django开发环境部署(一)——pip、virtualenv、virtualenvwrapper
- 易瑞沙(Iressa)血液ctDNA伴随诊断
- 第一次写博客
- ubuntu root用户默认密码
- linux关于bashrc与profile的区别(转)
- 数据结构14-排序方法之快速排序的实例
- centos的用户、组权限、添加删除用户等操作的详细操作命令
- CSS