Alternative PHP Cache
Introducere
The Alternative PHP Cache (APC) is a free and open opcode cache for PHP. It was conceived of to provide a free, open, and robust framework for caching and optimizing PHP intermediate code.
Instalarea
Această extensie » PECL nu este încorporată în PHP.
Informaţie despre instalarea acestei extensii PECL poate fi găsită în capitolul manualului, întitulat Instalarea extensiilor PECL. Informaţii adiţionale, cum ar fi lansări noi, descărcări, fişiere-sursă, informaţii despre persoana care întreţine extensia şi istoria schimbărilor poate fi localizată aici: » https://pecl.php.net/package/apc.
Biblioteca DLL pentru această extensie PECL poate fi descărcată de pe pagina » PHP Downloads sau de pe » https://pecl4win.php.net/
Notă: On Windows, APC needs a temp path to exist, and be writable by the web server. It checks TMP, TEMP, USERPROFILE environment variables in that order and finally tries the WINDOWS directory if none of those are set.
Notă: For more in-depth, highly technical implementation details, see the » developer-supplied TECHNOTES file .
Configuraţia la rulare
Comportamentul acestor funcţii este afectat de parametrii stabiliţi în php.ini.
Although the default APC settings are fine for many installations, serious users should consider tuning the following parameters.
There are two main decisions you have to make. First, how much shared memory do you want to set aside for APC, and second, whether you want APC to check if a file has been modified on every request. The two ini directives involved here are apc.shm_size and apc.stat. Read the sections on these two directives carefully below.
Once you have a running server, you should copy the apc.php script that comes with the extension to somewhere in your docroot and load it up in your browser. It provides you with a detailed look at what is happening in your cache. If you have GD enabled in PHP, it will even have pretty graphs. First thing to check is of course that it is actually caching files. Assuming it is working you should then pay close attention to the Cache full count number on the left. That tells you the number of times the cache has filled up and has had to forcefully clean up any entries not accessed within the last apc.ttl seconds. You should configure your cache to minimize this number. If you are constantly filling your cache, the resulting cache churn is going to hurt performance. You should either set more memory aside for APC, or use apc.filters to cache fewer scripts.
Name | Default | Changeable | Changelog |
---|---|---|---|
apc.enabled | "1" | PHP_INI_SYSTEM | PHP_INI_SYSTEM in APC 2. PHP_INI_ALL in APC <= 3.0.12. |
apc.shm_segments | "1" | PHP_INI_SYSTEM | |
apc.shm_size | "30" | PHP_INI_SYSTEM | |
apc.optimization | "0" | PHP_INI_ALL | PHP_INI_SYSTEM in APC 2. Removed in APC 3.0.13. |
apc.num_files_hint | "1000" | PHP_INI_SYSTEM | |
apc.user_entries_hint | "4096" | PHP_INI_SYSTEM | Available since APC 3.0.0. |
apc.ttl | "0" | PHP_INI_SYSTEM | Available since APC 3.0.0. |
apc.user_ttl | "0" | PHP_INI_SYSTEM | Available since APC 3.0.0. |
apc.gc_ttl | "3600" | PHP_INI_SYSTEM | |
apc.cache_by_default | "1" | PHP_INI_ALL | PHP_INI_SYSTEM in APC <= 3.0.12. Available since APC 3.0.0. |
apc.filters | NULL | PHP_INI_SYSTEM | |
apc.mmap_file_mask | NULL | PHP_INI_SYSTEM | |
apc.slam_defense | "0" | PHP_INI_SYSTEM | Available since APC 3.0.0. |
apc.file_update_protection | "2" | PHP_INI_SYSTEM | Available since APC 3.0.6. |
apc.enable_cli | "0" | PHP_INI_SYSTEM | Available since APC 3.0.7. |
apc.max_file_size | "1M" | PHP_INI_SYSTEM | Available since APC 3.0.7. |
apc.stat | "1" | PHP_INI_SYSTEM | Available since APC 3.0.10. |
apc.write_lock | "1" | PHP_INI_SYSTEM | Available since APC 3.0.11. |
apc.report_autofilter | "0" | PHP_INI_SYSTEM | Available since APC 3.0.11. |
apc.include_once_override | "0" | PHP_INI_SYSTEM | Available since APC 3.0.12. |
apc.rfc1867 | "0" | PHP_INI_SYSTEM | Available since APC 3.0.13. |
apc.rfc1867_prefix | "upload_" | PHP_INI_SYSTEM | |
apc.rfc1867_name | "APC_UPLOAD_PROGRESS" | PHP_INI_SYSTEM | |
apc.rfc1867_freq | "0" | PHP_INI_SYSTEM | |
apc.localcache | "0" | PHP_INI_SYSTEM | Available since APC 3.0.14. |
apc.localcache.size | "512" | PHP_INI_SYSTEM | Available since APC 3.0.14. |
Iată o explicaţie pe scurt a directivelor de configurare.
- 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.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.
- 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.
- 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.
- 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.
- apc.user_entries_hint integer
-
Just like apc.num_files_hint, a "hint" about the number of distinct user cache variables to store. Set to zero or omit if not sure.
- 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.
- apc.user_ttl integer
-
The number of seconds a user 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.
- apc.gc_ttl integer
-
The number of seconds that a cache entry may remain on the garbage-collection list. This value provides a fail-safe 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.
- 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.
Deprecated by apc.write_lock.
- 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