This article mainly introduces 2 sets of PHP APC configuration files and detailed parameters. Friends who need it can refer to
1. Install APC
The compilation parameters are as follows:
./configure --enable-apc --enable-apc-spinlocks --disable-apc-pthreadmutex
I won’t go into the installation process, the standard PHP extension installation mode.
2. 2 sets of configuration files
High performance, not suitable for frequent updates:
apc.enabled=1 apc.stat = 0 apc.stat_ctime = 0 apc.shm_size = 64M apc.shm_segments = 1 apc.num_files_hint = 1000 apc.ttl = 0 apc.slam_defense = 0 apc.write_lock = 1 apc.file_update_protection = 2
Slightly lower performance:
apc.enabled=1 apc.stat = 1 apc.stat_ctime = 1 apc.shm_size = 64M apc.shm_segments = 1 apc.num_files_hint = 1000 apc.ttl = 86400 apc.slam_defense = 0 apc.write_lock = 1 apc.file_update_protection = 2
The key to the 2 sets of configurations is apc.stat. After it is turned on, APC will not check whether the file is updated, so you can Reduce a large number of unnecessary system calls.
However, for newly released problems, PHP needs to be restarted. You can choose according to the situation.
In addition, attach a parameter description:
apc.enabled boolean
apc.enabled can be set to 0 to disable APC. It is mainly used when APC is statically compiled into PHP, because there is no other way to disable it (compiled as DSO, you can comment out the extension line in php.ini).
apc.shm_segments integer
The number of shared memory blocks to be allocated by the compiler cache. If APC runs out of shared memory but has set apc.shm_size to the maximum allowed by the system, you can try increasing this value.
apc.shm_size integer
The size of each shared memory block in MB. Some systems (including most BSD variants) have a very low shared memory block size by default.
apc.optimization integer
Optimization level. Set to 0 to disable the optimizer, higher values to use more aggressive optimization. Expect very limited speed improvements. Still in testing.
apc.num_files_hint integer
A rough estimate of the number of different origin files that are included or requested on the Web server. Set to 0 or remove this option if unsure; this setting is mainly used on sites with thousands of source files.
apc.user_entries_hint integer
Similar to apc.num_files_hint, stores cache variables based on the number of unique users. If unsure, set it to 0 or remove this item.
apc.ttl integer
The number of seconds the cache entry is allowed to stay in the buffer. 0 means never times out. The recommended value is 7200~86400. Setting it to 0 means that the buffer may be filled with old cache entries, resulting in the inability to cache new entries.
apc.user_ttl integer
Similar to apc.ttl, but for each user, the recommended value is 7200~86400. Setting to 0 means that the buffer may fill up with old cache entries, preventing new entries from being cached. If greater than 0, APC will attempt to delete expired entries.
apc.gc_ttl integer
The number of seconds the cache entry can exist in the garbage collection table. This value provides a safety measure that if the file is modified while the server process is executing a cached source file, the older version will not be recycled until this TTL is reached. Set to zero to disable this feature.
apc.cache_by_default boolean
The default is on, but it can be set to off and used together with apc.filters starting with a plus sign, then the file will only be cached when matching the filter .
apc.filters string
A comma-separated list of POSIX extended regular expressions. If any of the patterns match the source file name, the file is not cached. Note that the file name used to match is the file name passed to include/require, not the absolute path. If the first character of the regular expression is t it means any file matching the expression will be cached, if the first character is - then any matches will not be cached. - is the default value and can be omitted.
apc.mmap_file_mask string
If MMAP support was compiled for APC using --enable-mmap (enabled by default), the value here is the mktemp-style file passed to the mmap module Mask (recommended value is "/tmp/apc.XXXXXX"). This mask is used to determine whether the memory mapped area should be file-backed or shared memory backed. For direct file-backed memory mapping, set it to look like "/tmp/apc.XXXXXX" (exactly 6 X's). To use POSIX-style shm_open/mmap you need to set it to "/apc.shm.XXXXXX". You can also set it to "/dev/zero" to use the kernel's "/dev/zero" interface for anonymously mapped memory. Not defining this directive forces the use of anonymous mapping.
apc.slam_defense integer
On a very busy server, whether starting a service or modifying a file, a race condition may result from multiple processes trying to cache a file at the same time. This option sets the percentage at which the process skips the caching step when processing files that have not been cached. For example, setting it to 75 means that there is a 75% probability of not caching when an uncached file is encountered, thereby reducing the chance of collision. Use of this directive is deprecated and is encouraged to be set to 0 to disable this feature. It is recommended to use the apc.write_lock instruction.
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 updates slowly 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 the 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 significant performance improvements. 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
Buffering for uploading files Item entry name prefix
apc.rfc1867_name string
Hidden form item name for uploaded files that need 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 reduces 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 handler, such as 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
Record the md5 value of the file
##apc.lazy_functions integer
Enable function lazy loading
apc.lazy_classes integer
Enable class lazy loading
The above is the entire content of this article. I hope it will be helpful to everyone's study. For more related content, please pay attention to the PHP Chinese website!
Related recommendations:
3 ways to generate random numbers in PHP
Comparison of commonly used framework functions in PHP
The above is the detailed content of Analysis of two sets of configuration files and parameters of PHP APC. For more information, please follow other related articles on the PHP Chinese website!