Use APC caching in PHP to optimize PHP programs

Source: Internet
Author: User
Tags anonymous apc garbage collection posix regular expression require

Alternative PHP cache (APC) is a free and publicly optimized code cache for PHP. It is used to provide a free, open and robust architecture to cache and optimize PHP's intermediate code.

Under Windows, the APC requires a c:\tmp directory, and the directory is writable to the WEB server process.

1. Installation:

Installed in PHP extension form.

2. Configure

Apc.enabled Boolean

Apc.optimization optimization

Options can be changed in the script

APC php.ini configuration Options Detailed

[APC]
; Alternative PHP cache for caching and optimizing PHP Intermediate code Apc.cache_by_default = On
; SYS
; Whether to enable buffering for all files by default.
; When set to off and used with a apc.filters instruction that starts with a plus sign, the file is cached only when the filter is matched.
APC.ENABLE_CLI = Off
; SYS
; Whether to enable the APC feature for the CLI version and open this directive only for testing and debugging purposes.
apc.enabled = On
; If APC is enabled, it is the only way to disable it if the APC is statically compiled into PHP.
Apc.file_update_protection = 2
; SYS
; When you modify a file on a running server, you should perform an atomic operation.
; That is, first write in a temporary file, and then rename the file (MV) to the final name.
; Programs such as text editors and CP, TAR, and so on, do not operate this way, resulting in the possibility of buffering the defective files.
; The default value of 2 indicates that when the file is accessed, it is not buffered if it finds that the modified time distance is less than 2 seconds.
; The unfortunate visitor may get the incomplete content, but the bad effect will not be magnified by the cache.
; If you can make sure that all of the update operations are atomic, you can turn off this feature with 0.
; If your system is slow to update due to a large number of IO operations, you need to increase this value.
Apc.filters =
; SYS
; A comma-delimited list of POSIX-extended regular expressions.
; If the source file name matches any one of the patterns, the file is not cached.
; Note that the filename 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 file that matches the expression will be cached.
; If the first character is "-", no matches are cached. "-" is the default value and can be omitted.
Apc.ttl = 0
; SYS
; The number of seconds the cache entry allowed to linger in the buffer. 0 means never times out. The recommended value is 7200~36000.
; A setting of 0 means that the buffer may be filled with old cache entries, resulting in the inability to cache new entries.
Apc.user_ttl = 0
; SYS
; Similar to Apc.ttl, the recommended value is 7200~36000 for each user.
; A setting of 0 means that the buffer may be filled with old cache entries, resulting in the inability to cache new entries.
Apc.gc_ttl = 3600
; SYS
; The number of seconds the cache entry can exist in the garbage collection table.
; This value provides a security measure, even if a server process crashes while executing the cached source files.
; And the source file has been modified, and the memory allocated for the old version will not be reclaimed until this TTL value is reached.
; Setting to zero disables this attribute.
Apc.include_once_override = Off
; SYS
; Keep off, or you may cause unexpected results.
Apc.max_file_size = 1M
; SYS
; Prevents files larger than this size from being cached.
Apc.mmap_file_mask =
; SYS
; If you use –enable-mmap (default enabled) to compile Mmap support for APC,
; The value here is the Mktemp-style file mask passed to the Mmap module (the recommended value is "/TMP/APC.") XXXXXX ").
; The mask is used to determine whether the memory-mapped area is to be file-backed or shared memory backed.
; For a direct file-backed memory mapping, set to "/TMP/APC." XXXXXX "appearance (exactly 6 x).
; To use POSIX-style shm_open/mmap, you need to set it to "/apc.shm.xxxxxx."
; You can also set the "/dev/zero" to use the kernel's "/dev/zero" interface for anonymous mapped memory.
; Not defining this directive means enforcing the use of anonymous mappings.
Apc.num_files_hint = 1000
; SYS
; The approximate number of different source files that may be included or requested on the Web server (the recommended value is 1024~4096).
; If you are unsure, set to 0; This setting is primarily used for sites that have thousands of source files.
apc.optimization = 0
; Optimization level (recommended value is 0).
; A positive integer value indicates that the optimizer is enabled, and the higher the value, the more aggressive optimization is used.
; Higher values may have very limited speed increases, but are still being tested.
Apc.report_autofilter = Off
; SYS
; Whether to log 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 (the recommended value is 1).
; If the APC runs out of shared memory and the Apc.shm_size directive is set to the maximum allowed by the system,
; You can try to increase 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 (against using the directive, it is recommended to use the Apc.write_lock Directive)
; On a very busy server, whether you start a service or modify a file,
; can result in competitive conditions because multiple processes attempt to cache a single file at the same time.
; This directive is used to set the percentage of cache steps that the process skips when processing files that are not cached.
; For example, set to 75 means that when you encounter a file that is not cached, 75% of the probability is not cached, thereby reducing the collision probability.
; Encourage set to 0来 disable this feature.
Apc.stat = On
; SYS
; Whether to enable script update checking.
; Change this instruction value to be very careful.
; The default value on means that the APC checks whether the script is updated every time the script is requested.
; If updated, the compiled content is automatically recompiled and cached. But doing so has a detrimental effect on performance.
; If set to OFF, the performance is significantly improved by not checking.
; But for the updated content to take effect, you must restart the Web server.
; This instruction is also valid for Include/require files. But it should be noted that
; If you are using a relative path, the APC must check every time it include/require to locate the file.
; Using an absolute path allows you to skip the check, so you are encouraged to use an absolute path for include/require operations.
Apc.user_entries_hint = 100
; SYS
; Similar to the Num_files_hint directive, just for each individual user.
; If you are unsure, set to 0.
Apc.write_lock = On
; SYS
; Whether write locks are enabled.
; On a very busy server, whether you start a service or modify a file,
; can result in competitive conditions because multiple processes attempt to cache a single file at the same time.
; Enabling this directive avoids the appearance of competitive conditions.
apc.rfc1867 = Off
; SYS
; After you open the directive, for each upload file that contains the Apc_upload_progress field just before the file field,
; APC will automatically create a Upload_ user cache entry (that is, the Apc_upload_progress field value).

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.