©
このドキュメントでは、 php中国語ネットマニュアル リリース
这些函数的行为受 php.ini 中的设置影响。
Although the default APCu settings are fine for many installations, serious users should consider tuning the following parameters.
There is one decision to be made configuring APCu. How much memory is going to be allocated to APCu. The ini directive that controls this is apc.shm_size Read the sections on this carefully below.
Once the server is running, the apc.php script that is bundled with the extension should be copied somewhere into the docroot and viewed with a browser as it provides a detailed analysis of the internal workings of APCu. If GD is enabled in PHP, it will even display some interesting graphs. If APCu is working, the Cache full count number (on the left) will display the number of times the cache has reached maximum capacity and has had to forcefully clean any entries that haven't been accessed in the last apc.ttl seconds. This number is minimized in a well-configured cache. If the cache is constantly being filled, and thusly forcefully freed, the resulting churning will have disparaging effects on script performance. The easiest way to minimize this number is to allocate more memory for APCu.
When APCu is compiled with mmap support (Memory Mapping), it will use only one memory segment, unlike when APCu is built with SHM (SysV Shared Memory) support that uses multiple memory segments. MMAP does not have a maximum limit like SHM does in /proc/sys/kernel/shmmax. In general MMAP support is recommeded because it will reclaim the memory faster when the webserver is restarted and all in all reduces memory allocation impact at startup.
名字 | 默认 | 可修改范围 | 更新日志 |
---|---|---|---|
apc.enabled | "1" | PHP_INI_SYSTEM | |
apc.shm_segments | "1" | PHP_INI_SYSTEM | |
apc.shm_size | "32M" | PHP_INI_SYSTEM | |
apc.entries_hint | "4096" | PHP_INI_SYSTEM | |
apc.ttl | "0" | PHP_INI_SYSTEM | |
apc.gc_ttl | "3600" | PHP_INI_SYSTEM | |
apc.mmap_file_mask | NULL | PHP_INI_SYSTEM | |
apc.slam_defense | "1" | PHP_INI_SYSTEM | |
apc.enable_cli | "0" | PHP_INI_SYSTEM | |
apc.use_request_time | "1" | PHP_INI_ALL | |
apc.serializer | "default" | PHP_INI_SYSTEM | |
apc.rfc1867 | "0" | PHP_INI_SYSTEM | |
apc.rfc1867_prefix | "upload_" | PHP_INI_SYSTEM | |
apc.rfc1867_name | "APC_UPLOAD_PROGRESS" | PHP_INI_SYSTEM | |
apc.rfc1867_freq | "0" | PHP_INI_SYSTEM | |
apc.rfc1867_ttl | "3600" | PHP_INI_SYSTEM | |
apc.coredump_unmap | "0" | PHP_INI_SYSTEM | |
apc.preload_path | NULL | PHP_INI_SYSTEM |
这是配置指令的简短说明。
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 apc.shm_size is set as high as the system allows, raising this value might prevent APC from exhausting its memory.
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.entries_hint
integer A "hint" about the number of distinct variables that might be stored. 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 APC's cache could potentially fill up with stale entries while newer entries won't be cached. In the event of a cache running out of available memory, the cache will be completely expunged if ttl is equal to 0. Otherwise, if the ttl is greater than 0, APC will attempt to remove expired entries.
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.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 determining 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.
apc.enable_cli
integer Mostly for testing and debugging. Setting this enables APC for the CLI version of PHP. Under normal circumstances, it is not ideal to create, populate and destroy the APC cache on every CLI request, but for various test scenarios it is useful to be able to enable APC for the CLI version of PHP easily.
apc.serializer
string Used to configure APC to use a third party serializer.
apc.rfc1867
boolean RFC1867 File Upload Progress hook handler is only available if APC was compiled against PHP 5.2.0 or later. When enabled, any file uploads which includes a field called APC_UPLOAD_PROGRESS before the file field in an upload form will cause APC to automatically create an upload_key user cache entry where key is the value of the APC_UPLOAD_PROGRESS form entry.
Note that the hidden field specified by APC_UPLOAD_PROGRESS must come before the file field, otherwise the upload progress will not work correctly.
Note that the file upload tracking is not threadsafe at this point, so new uploads that happen while a previous one is still going will disable the tracking for the previous.
Note that the rate is only available once all file transfers are completed.
Example #1 An apc.rfc1867 example
<?php
print_r ( apcu_fetch ( "upload_ $_POST [ APC_UPLOAD_PROGRESS ] " ));
?>
以上例程的输出类似于:
Array ( [total] => 1142543 [current] => 1142543 [rate] => 1828068.8 [filename] => test [name] => file [temp_filename] => /tmp/php8F [cancel_upload] => 0 [done] => 1 )
apc.rfc1867_prefix
string Key prefix to use for the user cache entry generated by rfc1867 upload progress functionality.
apc.rfc1867_name
string Specify the hidden form entry name that activates APC upload progress and specifies the user cache key suffix.
apc.rfc1867_freq
string The frequency that updates should be made to the user cache entry for upload progress. This can take the form of a percentage of the total file size or a size in bytes optionally suffixed with "k", "m", or "g" for kilobytes, megabytes, or gigabytes respectively (case insensitive). A setting of 0 updates as often as possible, which may cause slower uploads.
apc.rfc1867_ttl
integer TTL for rfc1867 entries.
apc.coredump_unmap
boolean Enables APC handling of signals, such as SIGSEGV, that write core files when signaled. When these signals are received, APC will attempt to unmap the shared memory segment in order to exclude it from the core file. This setting may improve system stability when fatal signals are received and a large APC shared memory segment is configured.
This feature is potentially dangerous. Unmapping the shared memory segment in a fatal signal handler may cause undefined behaviour if a fatal error occurs.
Note:
Although some kernels may provide a facility to ignore various types of shared memory when generating a core dump file, these implementations may also ignore important shared memory segments such as the Apache scoreboard.
apc.preload_path
string Optionally, set a path to the directory that APC will load cache data at startup.
apc.use_request_time
bool Use the SAPI request start time for TTL.