参见官方文档
http://php.net/manual/en/book.apc.php
The Alternative PHP Cache (APC) is a free and open opcode cache for PHP. Its goal is to provide a free, open, and robust framework for caching and optimizing PHP intermediate code.
通过以下方式可以查看是否安装了APC扩展
$ php -r ‘phpinfo();‘ |grep apc apc apc.cache_by_default => On => On apc.canonicalize => On => On apc.coredump_unmap => Off => Off apc.enable_cli => Off => Off apc.enabled => On => On apc.file_md5 => Off => Off apc.file_update_protection => 2 => 2 apc.filters => no value => no value apc.gc_ttl => 3600 => 3600 apc.include_once_override => Off => Off apc.lazy_classes => Off => Off apc.lazy_functions => Off => Off apc.max_file_size => 1M => 1M apc.mmap_file_mask => no value => no value apc.num_files_hint => 1000 => 1000 apc.preload_path => no value => no value apc.report_autofilter => Off => Off apc.rfc1867 => Off => Off apc.rfc1867_freq => 0 => 0 apc.rfc1867_name => APC_UPLOAD_PROGRESS => APC_UPLOAD_PROGRESS apc.rfc1867_prefix => upload_ => upload_ apc.rfc1867_ttl => 3600 => 3600 apc.serializer => default => default apc.shm_segments => 1 => 1 apc.shm_size => 32M => 32M apc.shm_strings_buffer => 4M => 4M apc.slam_defense => On => On apc.stat => On => On apc.stat_ctime => Off => Off apc.ttl => 0 => 0 apc.use_request_time => On => On apc.user_entries_hint => 4096 => 4096 apc.user_ttl => 0 => 0 apc.write_lock => On => On
1.安装APC扩展
tar -zxvf APC-3.1.14.tgz
cd APC-3.1.14
phpize
./configure --with-php-config=/data/app_platform/php/bin/php-config
make && make install
2.配置php.ini
以下是建议使用的参数
extension=apc.so
apc.enabled=1
apc.shm_size=128M
apc.ttl=7200
apc.user_ttl=7200
apc.enable_cli=1
3.配置APC参数
参考文档
http://php.net/manual/en/apc.configuration.php
有两个首要考虑的问题是:1.给APC分配多少内存空间。2.对于每个请求是否让APC检查一个文件是否被更改。这个两个参数是apc.shm_size和apc.stat
APC自带一个监控页面apc.php,可以从源码包中复制apc.php到一个nginx虚拟主机,然后通过http://xxxxxx/apc.php查看APC缓存的状态。
如果安装PHP的GD扩展,则可以看到图表
apc.shm_size