PHP APC缓存安装配置教程
PHP APC提供两种缓存功能,即缓存Opcode(目标文件),我们称之为apc_compiler_cache,同时它还提供一些接口用于PHP开发人员将用户数据驻留在内存中,我们称之为apc_user_cache,下面我们来看看PHP APC缓存安装配置.
最简单的方法,找到php安装目录的pecl
自动安装
# /usr/local/php/bin/pecl install apc
接下来按提示一步步完成即可
然后配置 /usr/local/php/etc/php.ini 末尾加入
extension=apc.so
手动安装
官网:http://cn2.php.net/manual/zh/book.apc.php
下载:http://pecl.php.net/package/APC 找最新的
下载apc
- # wget http://pecl.php.net/get/APC-3.1.13.tgz
- # tar -zxvf APC-3.1.13.tgz
- # cd APC-3.1.13
生成configure文件
# /usr/local/php/bin/phpize
执行configure 并且 make && make install
- # ./configure --enable-apc --enable-apc-mmap --with-php-config=/usr/local/php/bin/php-config
- # make
- # make install
拷贝添加SO文件
- # cp /usr/local/php/lib/php/extensions/no-debug-non-zts-20100525/apc.so /usr/local/php/lib/php/extensions/apc.so
- # chmod 755 /usr/local/php/lib/php/extensions/apc.so
修改php.ini使之启动APC模块
- # vi /usr/local/php/etc/php.ini
- extension_dir = "/usr/local/php/lib/php/extensions"
- extension=apc.so //开源软件:phpfensi.com
- 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
# service httpd restart
使用APC test.php
- <?php
- print_r(apc_cache_info());
- 注意 在浏览器看会不是很友好,可以查看网页源代码就看到很清晰
- Array
- (
- [num_slots] => 1031
- [ttl] => 0
- [num_hits] => 3
- [num_misses] => 1
- [num_inserts] => 1
- [expunges] => 0
- [start_time] => 1398341530
- [mem_size] => 4240
- [num_entries] => 1
- [file_upload_progress] => 1
- [memory_type] => mmap
- [locking_type] => pthread mutex Locks
- [cache_list] => Array
- (
- [0] => Array
- (
- [type] => file
- [device] => 64768
- [inode] => 1179758
- [filename] => /data/www/www.111cn.net /test.php
- [num_hits] => 3
- [mtime] => 1398341609
- [creation_time] => 1398341617
- [deletion_time] => 0
- [access_time] => 1398341630
- [ref_count] => 1
- [mem_size] => 4240
- )
- )
- [deleted_list] => Array
- (
- )
- [slot_distribution] => Array
- (
- [109] => 1
- )
- )
多次点击,可以发现 num_hits 在变化,说明缓存命中了!
压力测试看效果,关闭开启apc分别压力测试对比一下你会发现开启apc之后吞吐率会比没开启apc要提高许多.
# ab -n1000 -c10 http://www.phpfensi.com/test.php