Home > Article > Backend Development > Detailed explanation of 2 sets of PHP APC configuration files and parameters_PHP tutorial
1. Install APC
Download http://pecl.php.net/get/APC-3.1.9.tgz
The compilation parameters are as follows:
2. 2 sets of configuration files
High performance, not suitable for frequent updates:
2套配置关键在于apc.stat, 开启后APC将不会检查文件是否更新, 这样可以减少大量不必要的系统调用.
但是, 对于新发布的问题 需要重新启动PHP. 可以根据情况选择.
另外, 附上参数说明:
apc.enabled boolean
apc.enabled 可以设成 0 来禁用 APC.主要是用在当 APC 被静态编译入 PHP 时,因为没有其它方法来禁用了(编译为 DSO , 的时候,可以将php.ini中的extension 行注释掉)。
apc.shm_segments integer
编译器缓存要分配的共享内存块的数目。如果 APC 用光了共享内存但是已经将 apc.shm_size 设为了系统所能允许的最大值,可以尝试增大此值。
apc.shm_size integer
以 MB 为单位的每个共享内存块的大小。默认时,有些系统(包括大多数 BSD 变种)的共享内存块大小非常低。
apc.optimization integer
优化级别。设为 0 则禁用优化器,更高的值则使用更主动的优化。期望非常有限的速度提升。尚在试验中。
apc.num_files_hint integer
Web 服务器上的被包含或被请求的不同源文件的数目的大概估计。如果不确定则设为 0 或去掉此项;此设定主要用在有数千个源文件的站点。
apc.user_entries_hint integer
与apc.num_files_hint类似, 根据唯一用户数来存储缓存变量。 如果不能确定则设置为0或或去掉此项。
apc.ttl integer
缓存条目在缓冲区中允许逗留的秒数。0 表示永不超时。建议值为7200~86400 设为 0 意味着缓冲区有可能被旧的缓存条目填满,从而导致无法缓存新条目。
apc.user_ttl integer
类似于apc.ttl,只是针对每个用户而言,建议值为7200~86400。 设为 0 意味着缓冲区有可能被旧的缓存条目填满,从而导致无法缓存新条目。 如果大于0,APC将尝试删除过期条目。
apc.gc_ttl integer
缓存条目在垃圾回收表中能够存在的秒数。此值提供了一个安全措施,即在服务器进程在执行缓存的源文件时,如果该文件被修改则旧版本将不会被回收,直到达到此 TTL 为止。设为零将禁用此特性。
apc.cache_by_default boolean
默认为 on,但可以设为 off 并和加号开头的 apc.filters 一起用,则文件仅在匹配过滤器时被缓存。
apc.filters string
一个以逗号分隔的 POSIX 扩展正则表达式的列表。如果任一个模式匹配源文件名,则该文件不被缓存。注意用来匹配的文件名是传递给 include/require 的文件名,而不是绝对路径。如果正则表达式的第一个字符是+ t则意味着任何匹配表达式的文件会被缓存,如果第一个字符是 - 则任何匹配项都不会被缓存。 -是默认值,可以省略掉。
apc.mmap_file_mask string
如果使用 --enable-mmap(默认启用)为APC编译了MMAP支持, 这里的值就是传递给mmap模块的mktemp风格的文件掩码(建议值为" /tmp/apc.XXXXXX")。 该掩码用于决定内存映射区域是否要被file-backed或者shared memory backed。 对于直接的file-backed内存映射,要设置成"/tmp/apc.XXXXXX"的样子(恰好6个X)。 要使用POSIX风格的shm_open/mmap就需要设置成"/apc.shm.XXXXXX"的样子。 你还可以设为"/dev/zero"来为匿名映射的内存使用内核的"/dev/zero"接口。 不定义此指令则表示强制使用匿名映射。
apc.slam_defense integer
在非常繁忙的服务器上,无论是启动服务还是修改文件, 都可能由于多个进程企图同时缓存一个文件而导致竞争条件。 这个选项用于设置进程在处理未被缓存的文件时跳过缓存步骤的百分率。 比如设为75表示在遇到未被缓存的文件时有75%的概率不进行缓存,从而减少碰撞几率。 反对使用该指令,鼓励设为 0来禁用这个特性。建议该用apc.write_lock指令。
Deprecated by apc.write_lock.
apc.file_update_protection integer
When you modify files on a running server, you should perform atomic operations. That is, first write to a temporary file, and then rename (mv) the file to the final name. Text editors and programs such as cp and tar do not operate in this way, resulting in the possibility of buffering incomplete files. The default value 2 means that when accessing a file, if the modification time is found to be less than 2 seconds from the access time, no buffering will be performed. The unlucky visitor may get corrupted content, but the bad effect is not magnified by caching. If you can ensure that all update operations are atomic, you can turn off this feature with 0. If your system is slow to update due to heavy IO operations, you may need to increase this value.
apc.enable_cli integer
Whether to enable APC functionality for the CLI version, turn this option on only for testing and debugging purposes. Under normal circumstances it is not ideal to create, populate and destroy the APC cache on every request to the CLI, but it is useful in various testing scenarios to be able to easily make a CLI version of PHP APC
apc.max_file_size integer
Default is 1M, files larger than this value will not be cached.
apc.stat integer
Whether to enable script update check. Be very careful when changing this command value. The default value On indicates that APC checks whether the script has been updated each time it is requested. If it is updated, it will automatically recompile and cache the compiled content. However, doing so has a negative impact on performance. If set to Off, no checking is performed, resulting in greatly improved performance. But in order for the updated content to take effect, you must restart the web server (Translator's Note: If you use cgi/fcgi, you need to restart the cgi/fcgi process). On production servers where script files rarely change, significant performance improvements can be achieved by disabling this option.
This directive is also valid for include/require files. But it should be noted that if you use a relative path, APC must check to locate the file every time include/require. Using absolute paths can skip the check, so you are encouraged to use absolute paths for include/require operations.
apc.write_lock boolean
On a busy server, when the web server is started for the first time, or many files are modified at the same time, APC may compile the same file multiple times File, write lock guarantees that only one process will attempt to compile and cache an uncached script. Other processes trying to use the script will not use the opcode cache, instead locking and waiting for the cache to be generated.
apc.report_autofilter boolean
Whether to record all scripts that are automatically not cached due to early/late binding reasons.
apc.include_once_override boolean
Optimize the include_once() and require_once() functions to avoid executing additional system calls.
apc.rfc1867 boolean
Enable monitoring file upload progress function
apc.rfc1867_prefix string
Buffer entry name prefix for uploading files
apc.rfc1867_name string
Hidden form item name of the uploaded file that needs to be processed by APC
apc.rfc1867_freq string
Update frequency of user uploaded file cache items. The value can be a percentage of the total file size, or an absolute size (case-insensitive) ending in "k", "m", or "g" kilobytes, megabytes, or gigabytes. 0 means the fastest possible update, but This may result in slower upload speeds.
apc.rfc1867_ttl bool
TTL for rfc1867 entries.
apc.localcache boolean
Use non-locking local process shadow-cache, which can reduce competition between locks when writing to the buffer.
apc.localcache.size integer
The size of the local process shadow-cache, should be set to a sufficiently large value, approximately half of apc.num_files_hint.
apc.coredump_unmap boolean
Enable APC signal handlers, such as the SIGSEGV signal, when the signal is written to the core file. When these signals are received, APC will attempt to unmap the shared memory segment, excluding it from the core file. This setting can improve system stability when receiving a fatal signal or using APC's large shared memory segment configuration.
apc.stat_ctime integer
Verifying ctime (creation time) can avoid problems caused by SVN or rsync and ensure that the inode has not changed since the last statistics. APC usually only checks mtime (modification time).
apc.canonicalize bool
If set to on, the relative path will be changed to an absolute path in no-state mode (no checking for file updates).
apc.preload_path string
apc.use_request_time bool
Use the SAPI request start time for TTL.
apc.file_md5 bool
The md5 value of the recorded file
apc.lazy_functions integer
Enable function lazy loading
apc.lazy_classes integer
Enable lazy loading of classes