最简单的方法,找到php安装目录的pecl 自动安装: #/usr/local/php/bin/pecl install apc 下面按提示一步步完成即可 配置 /etc/php.ini 末尾加入 extension=apc.so 手动安装: 官网http://cn2.php.net/manual/zh/book.apc.php 下载http://pecl.php.net/packa
最简单的方法,找到php安装目录的pecl
自动安装:
# /usr/local/php/bin/pecl install apc
下面按提示一步步完成即可
配置/etc/php.ini 末尾加入
extension=apc.so
手动安装:
官网 http://cn2.php.net/manual/zh/book.apc.php
下载http://pecl.php.net/package/APC 找最新的
#wget http://pecl.php.net/get/APC-3.1.9.tgz
# tar -zxvf APC-3.1.9.tgz
# cd APC-3.1.9
# /usr/local/php/bin/phpize (生产configure文件)
# ./configure –enable-apc –enable-apc-mmap –with-php-config=/usr/local/php/bin/php-config
# make
# make install
拷贝添加SO文件
# cp /usr/local/lib/php/extensions/no-debug-zts-20060613/apc.so /usr/local/php/lib/php/extensions/apc.so
# chmod 755 /usr/local/php/lib/php/extensions/apc.so
修改PHP.INI使之启动APC模块
修改 php.ini下
extension_dir = “./”
extension_dir = “/usr/local/php/lib/php/extensions”
配置/etc/php.ini 末尾加入
extension=apc.so
apc.enabled = 1
apc.cache_by_default = on
apc.shm_segments = 1
apc.shm_size = 128
apc.ttl = 7200
apc.user_ttl = 7200
apc.num_files_hint = 1024
apc.write_lock = On
apc.gc_ttl=3600
apc.ttl=0
apc.mmap_file_mask=/tmp/apc.XXXXXX
重启apache
#/usr/local/apache2/bin/apachectl restart
使用APC
print_r(apc_cache_info());
?>
注意 在浏览器看会不是很友好,可以查看网页源代码就看到很清晰
Array ( [num_slots] => 1031 [ttl] => 0 [num_hits] => 4 [num_misses] => 1 [num_inserts] => 1 [expunges] => 0 [start_time] => 1322818377 [mem_size] => 4240 [num_entries] => 1 [file_upload_progress] => 1 [memory_type] => mmap [locking_type] => spin Locks [cache_list] => Array ( [0] => Array ( [type] => file [device] => 2049 [inode] => 883230 [filename] => /var/www/tb.php [num_hits] => 4 [mtime] => 1322818340 [creation_time] => 1322818379 [deletion_time] => 0 [access_time] => 1322818482 [ref_count] => 1 [mem_size] => 4240 ) ) [deleted_list] => Array ( ) [slot_distribution] => Array (
... ...
多次点击,可以发现num_hits在变化,说明缓存命中了!
压力测试看效果:
怎么压力测试看之前的文章 http://blog.csdn.net/21aspnet/article/details/6595984
先看看关闭apc功能,在php.ini中配置
# ab -n1000 -c10 http://localhost/tb.php
这个时候吞吐率Requests per second 比没用之前提高许多
==========
另外几款php缓存工具
Xcache
http://xcache.lighttpd.net/
eAccelerator
http://sourceforge.net/projects/eaccelerator/