PHP 加速器 之 APC

下载地址:http://pecl.php.net/package/APC

 

配置详解:

apc.enabled boolean

apc.enabled can be set to 0 to disable APC. This is primarily useful when APC is statically compiled into PHP, since there is no other way to disable it (when compiled as a DSO, the extension line in php.ini can just be commented-out).
通过设置apc.enabled = 0 来禁用apc,这主要是当apc已经被静态编译到了php里了而又不想使用时很有用,因为没有其他的办法来禁用了

apc.shm_segments integer

The number of shared memory segments to allocate for the compiler cache. If APC is running out of shared memory but you have already set apc.shm_size as high as your system allows, you can try raising this value. Setting this to a  value other than 1 has no effect in mmap mode since mmap’ed shm segments don’t have size limits.(Default: 1)
这里设置可以使用多少个共享内存段,当一个共享内存段分配到系统允许的最大值还不够用时,就可以通过该项设置多个共享内存段,以增加缓存的大小;注意:使用mmap模式时,大于1的值是没有任何作用的,因为mmap的内存段是不受限制的;默认值为1

apc.shm_size integer

The size of each shared memory segment in MB. By default, some systems (including most BSD variants) have very low limits on the size of a shared memory segment.
设置每个共享内存段的大小,单位为MB

apc.optimization integer

The optimization level. Zero disables the optimizer, and higher values use more aggressive optimizations. Expect very modest speed improvements. This is experimental.
设置优化级别,0为不优化,值越大,优化级别越高,但是如果代码写的不太好,优化级别太高,难免会出问题。

apc.num_files_hint integer

A "hint" about the number of distinct source files that will be included or requested on your web server. Set to zero or omit if you’re not sure; this setting is mainly useful for sites that have many thousands of source files.
应该是最多允许缓存多少个文件的意思,默认为1024个;(如果我翻译的有问题可以留言)

apc.ttl integer

The number of seconds a cache entry is allowed to idle in a slot in case this cache entry slot is needed by another entry. Leaving this at zero means that your cache could potentially fill up with stale entries while newer entries won’t be cached.
如果缓存空间不够时,将清除缓存时间大于ttl(单位为:s)的一些cache来缓存新的文件,如果没有缓存时间大于ttl的cache或该ttl设置为0时,新的访问将不会被cache

apc.gc_ttl integer

The number of seconds that a cache entry may remain on the garbage-collection list. This value provides a failsafe in the event that a server process dies while executing a cached source file; if that source file is modified, the memory allocated for the old version will not be reclaimed until this TTL reached. Set to zero to disable this feature.
{不知道啥意思}

apc.cache_by_default boolean

On by default, but can be set to off and used in conjunction with positive apc.filters so that files are only cached if matched by a positive filter.
默认缓存任何可以缓存的文件,如果设置为off,将根据apc.filter来缓存允许缓存的文件

apc.filters string

A comma-separated list of POSIX extended regular expressions. If any pattern matches the source filename, the file will not be cached. Note that the filename used for matching is the one passed to include/require, not the absolute path. If the first character of the expression is a + then the expression will be additive in the sense that any files matched by the expression will be cached, and if the first character is a then anything matched will not be cached. The case is the default, so it can be left off.
是逗号分隔的正则表达式的列表,匹配的是文件名,后面的加号表示缓存,减号表示不缓存{现在没时间了,具体用法以后补充}

apc.mmap_file_mask string

If compiled with MMAP support by using –enable-mmap this is the mktemp-style file_mask to pass to the mmap module for determing whether your mmap’ed memory region is going to be file-backed or shared memory backed. For straight file-backed mmap, set it to something like /tmp/apc.XXXXXX (exactly 6 Xs). To use POSIX-style shm_open/mmap put a .shm somewhere in your mask. e.g. /apc.shm.XXXXXX You can also set it to /dev/zero to use your kernel’s /dev/zero interface to anonymous mmap’ed memory. Leaving it undefined will force an anonymous mmap.

apc.slam_defense integer

On very busy servers whenever you start the server or modify files you can create a race of many processes all trying to cache the same file at the same time. This option sets the percentage of processes that will skip trying to cache an uncached file. Or think of it as the probability of a single process to skip caching. For example, setting apc.slam_defense to 75 would mean that there is a 75% chance that the process will not cache an uncached file. So, the higher the setting the greater the defense against cache slams. Setting this to 0 disables this feature.

apc.file_update_protection integer

When you modify a file on a live web server you really should do so in an atomic manner. That is, write to a temporary file and rename (mv) the file into its permanent position when it is ready. Many text editors, cp, tar and other such programs don’t do this. This means that there is a chance that a file is accessed (and cached) while it is still being written to. This apc.file_update_protection setting puts a delay on caching brand new files. The default is 2 seconds which means that if the modification timestamp (mtime) on a file shows that it is less than 2 seconds old when it is accessed, it will not be cached. The unfortunate person who accessed this half-written file will still see weirdness, but at least it won’t persist. If you are certain you always atomically update your files by using something like rsync which does this correctly, you can turn this protection off by setting it to 0. If you have a system that is flooded with io causing some update procedure to take longer than 2 seconds, you may want to increase this a bit.

apc.enable-cli integer

Mostly for testing and debugging. Setting this enables APC for the CLI version of PHP. Normally you wouldn’t want to create, populate and tear down the APC cache on every CLI request, but for various test scenarios it is handy to be able to enable APC for the CLI version of APC easily.

安装:
tar xvf apc_x.y.tar
cd apc_x.y
./configure –enable-apc  –enable-apc-mmap
make
make install

配置:

  extension=apc.so
  apc.enabled=1
  apc.shm_segments=1
  apc.shm_size=128
  apc.ttl=7200
  apc.user_ttl=7200
  apc.num_files_hint=1024
  apc.mmap_file_mask=/tmp/apc.XXXXXX
  apc.enable_cli=1

使用:

1. 源码里都有一个apc.php ,放到网站目录下,可以通过给文件知道apc的使用情况

留下评论

邮箱地址不会被公开。 必填项已用*标注

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据