PHP扩展APC参数优化
编辑 php.ini在下面输入
apc.enabled=1
apc.shm_segments = 1
apc.shm_size = 1G
apc.ttl = 0
apc.user_ttl = 0
apc.num_files_hint = 1000
apc.write_lock=1
apc.slam_defense=60
apc.stat = 1
apc.max_file_size=1M
apc.cache_by_default=1
apc.filters = NULL
请解释
apc.enabled open apc 设置为 0 为关闭,1 为打开
apc.shm_segments 共享内存块数
apc.shm_size 共享内存大小,可以设置1G,那么显然共享内存的总数就是apc.shm_segments*apc.shm_size
apc.num_files_hint 允许缓存多少个操作码(即项目中有多少个php文件)
apc.stat为1时,会自动检查opcode对应的php文件是否有更新。如果有更新,会自动更新。如果设置为0则不勾选,这样会提高apc的效率,但是要让php的修改生效,必须重启apache,或者使用函数apc_cache_clear()来清除缓存(我的之后自己测试,设置为1或0对qps影响不大,所以最好设置为1,以免每次改文件都清缓存)
apc.ttl opcode缓存过期时间,设置为0表示不过期,如果不为0会检查两次请求之间的时间,如果时间大于设置值,则更新opcode缓存(这个比较影响效率,建议设置为 0 )
apc.write_lock 表示当多个进程同时更新一个opcode缓存时,只有第一个生效,可以有效避免写冲突
apc.max_file_size 超过设定大小的文件不会被缓存
apc.filters 需要特殊文件,多个文件用逗号(,)分隔
apc.filters 与 apc.cache_by_default 结合使用,
当 apc.cache_by_default 为 1 时,不缓存 apc.filters 文件,当 apc.cache_by_default 为 0 时,仅缓存 apc.filters 文件
apc.slam_defense 当你的网站并发量很大时,可能会出现http daemon fork的多个子进程同时缓存相同的Opcodes的情况。通过 apc.slam_defense,您可以减少这种情况发生的机会。比如apc.slam_defense的值设置为60时,遇到uncached Opcodes时,每100次就有60个uncached opcodes。
(Edit PHP ini
Enter below
apc. enabled=1
apc. shm_ segments = 1
apc. shm_ size = 1G
apc. ttl = 0
apc. user_ ttl = 0
apc. num_ files_ hint = 1000
apc. write_ lock=1
apc. slam_ defense=60
apc. stat = 1
apc. max_ file_ size=1M
apc. cache_ by_ default=1
apc. filters = NULL
Please explain
apc. Enabled open APC is set to 0 to close and 1 to open
apc. shm_ Segments number of shared memory blocks
apc. shm_ Size shared memory size, 1g can be set, so it is obvious that the total number of shared memory is APC shm_ segments*apc. shm_ size
apc. num_ files_ How many opcodes does hint allow to cache (that is, how many PHP files are there in the project)
apc. When stat is 1, it will automatically check whether the PHP file corresponding to opcode is updated. If there is an update, it will be updated automatically. If it is set to 0, it will not be checked, which will improve the efficiency of APC. However, for the PHP modification to take effect, you must restart Apache or use the function APC_ cache_ Clear() to clear the cache (after my own test, setting it to 1 or 0 has little impact on QPS, so it's best to set it to 1 to avoid clearing the cache every time I change the file)
apc. TTL opcode cache expiration time. If it is set to 0, it means it will not expire. If it is not set to 0, the time between two requests will be checked. If the time is greater than the set value, the opcode cache will be updated (this comparison affects efficiency, and it is recommended to set it to 0)
apc. write_ Lock means that when multiple processes update an opcode cache at the same time, only the first one takes effect, which can effectively avoid write conflicts
apc. max_ file_ Files whose size exceeds the set size will not be cached
apc. Filters requires special files. Multiple files are separated by commas (,)
apc. Filters and APC cache_ by_ Used in combination with default,
When APC cache_ by_ When default is 1, APC is not cached Filters file, when APC cache_ by_ When the default is 0, only APC is cached Filters file
apc. slam_ When your website has a large amount of concurrency, multiple sub processes of HTTP daemon fork may cache the same opcodes at the same time. Through APC slam_ Defense, you can reduce the chance of this happening. For example, APC slam_ When the value of defense is set to 60, when encountering uncached opcodes, there are 60 uncached opcodes every 100 times.
)
页:
[1]