Home >Backend Development >PHP Tutorial >Detailed explanation of APC configuration_PHP tutorial
I. APC installation configuration
Refer to my article
II. Detailed explanation of the php.ini configuration item [APC] section
[apc]
; alternative php cache is used to cache and optimize php intermediate code
apc.cache_by_default = on
;sys
; Whether to enable buffering by default for all files.
; If set to off and used with the apc.filters directive starting with a plus sign, files will only be cached if they match the filter.
apc.enable_cli = off
;sys
; Whether to enable apc functionality for the cli version, turn this directive on only for testing and debugging purposes.
apc.enabled = on
; Whether to enable apc. If apc is statically compiled into php and you want to disable it, this is the only way.
apc.file_update_protection = 2
;sys
; 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 amplified 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.filters =
;sys
; A comma-separated list of POSIX extended regular expressions.
; If the source file name matches any of the patterns, 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 "+" it means that any files 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.ttl = 0
;sys
; The number of seconds a cache entry is allowed to stay in the buffer. 0 means never times out. The recommended value is 7200~36000.
; Setting to 0 means that the buffer may become filled with old cache entries, preventing new entries from being cached.
apc.user_ttl = 0
;sys
; Similar to apc.ttl, but for each user, the recommended value is 7200~36000.
; Setting to 0 means that the buffer may become filled with old cache entries, preventing new entries from being cached.
apc.gc_ttl = 3600
;sys
; The number of seconds a cache entry can exist in the garbage collection table.
; This value provides a safety measure even if a server process crashes while executing a cached source file,
; and the source file has been modified, the memory allocated for the old version will not be reclaimed until this ttl value is reached.
; Set to zero to disable this feature.
apc.include_once_override = off
;sys
; There is currently no documentation for this command, see: http://pecl.php.net/bugs/bug.php?id=8754
; Please keep it off, otherwise it may cause unexpected results.
apc.max_file_size = 1m
;sys
; Prevent files larger than this size from being cached.
apc.mmap_file_mask =
;sys
; If mmap support is compiled for apc using --enable-mmap (enabled by default),
; The value here is the mktemp-style file mask passed to the mmap module (the 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 "/tmp/apc.xxxxxx" (exactly 6 x's).
; To use posix-style shm_open/mmap, it needs to be set to "/apc.shm.xxxxxx".
; You can also set 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.num_files_hint = 1000
;sys
; The approximate number of different source files that may be included or requested on the web server (recommended value is 1024~4096).
; If you are not sure, set to 0; This setting is mainly used for sites with thousands of source files.
apc.optimization = 0
; Optimization level (recommended value is 0).
; A positive integer value enables the optimizer, with higher values using more aggressive optimizations.
; Higher values may have very limited speed improvements, but are currently experimental.
apc.report_autofilter = off
;sys
; Whether to record all scripts that are automatically not cached due to early/late binding reasons.
apc.shm_segments = 1
;sys
; The number of shared memory blocks allocated for the compiler buffer (recommended value is 1).
; If apc has exhausted shared memory and the apc.shm_size directive has been set to the maximum allowed by the system,
; You can try increasing this value.
apc.shm_size = 30
;sys
; The size of each shared memory block (in MB, the recommended value is 128~256).
; Some systems (including most BSD variants) have a very small default shared memory block size.
apc.slam_defense = 0
;sys (It is against the use of this command, it is recommended to use the apc.write_lock command)
; On a very busy server, whether starting a service or modifying a file,
; can cause a race condition due to multiple processes trying to cache a file at the same time.
; This directive is used to set the percentage at which the process skips the caching step when processing uncached files.
; 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.
; Encouraged to be set to 0 to disable this feature.
apc.stat = on
;sys
; Whether to enable script update checking.
; Be very careful when changing this directive value.
; The default value on means that apc checks whether the script has been updated every time it is requested,
; Automatically recompile and cache the compiled content if updated. However, doing so has a negative impact on performance.
; If set to off, no checking is performed, thus greatly improving performance.
; But in order for the updated content to take effect, you must restart the web server.
; This directive is also valid for include/require files. But it should be noted that
; If you use relative paths, apc must check to locate the file every include/require.
; Using absolute paths can skip the check, so you are encouraged to use absolute paths for include/require operations.
apc.user_entries_hint = 100
;sys
; Similar to the num_files_hint directive, but for each different user.
; If you are not sure, set to 0.
apc.write_lock = on
;sys
; Whether to enable write lock.
; On a very busy server, whether starting a service or modifying a file,
; can cause a race condition due to multiple processes trying to cache a file at the same time.
; Enable this directive to avoid race conditions.
apc.rfc1867 = off
;sys
; After turning on this directive, for each uploaded file that contains the apc_upload_progress field just before the file field,
; apc will automatically create a user cache entry for upload_ (which is the apc_upload_progress field value).
III. Function:
apc_cache_info - retrieves cached information (and meta-data) from apc's data store
apc_clear_cache - clears the apc cache
apc_define_constants - defines a set of constants for later retrieval and mass-definition
apc_delete - removes a stored variable from the cache
apc_fetch - fetch a stored variable from the cache
apc_load_constants - loads a set of constants from the cache
apc_sma_info - retrieves apc's shared memory allocation information
apc_store - cache a variable in the data store
The usage of apc is relatively simple, with only a few functions, listed below.
apc_cache_info () returns cache information
apc_clear_cache() clears the apc cache content.
By default (no parameters), only the system cache is cleared. To clear the user cache, the ‘user’ parameter is required.
apc_define_constants (string key, array constants [, bool case_sensitive]) Add array constants to the cache as constants.
apc_load_constants (string key).
Remove the constant cache.
apc_store ( string key, mixed var [, int ttl] ).
Save data in cache.
apc_fetch(string key).
Get the cache content saved by apc_store
apc_delete(string key).
Delete the content saved by apc_store.
IV. apc management
Go to pecl.php.net to download the apc source code package, there is apc.php, copy it to a place where your web server can access it, and browse to access it.
Management interface functions include:
1. refresh data
2. view host stats
3. system cache entries
4. user cache entries
5. version check
Pay attention to this tool in Section 4, it is very useful