PHP cache module cache (APC)

Source: Internet
Author: User
Tags apc apc module

PHP cache module cache (APC)

APC is short for Alternative PHP Cache, which is a free and public Optimized Code Cache of PHP. It is used to provide free, public, and robust architectures to cache and optimize PHP intermediate code.

1. Configure APC in PHP

To enable the APC module, remove the comments before extension = php_apc.dll.
The configuration parameters of the APC module are as follows:

Apc. enabled

Type: Boolean
Apc. enabled can be set to 0 to disable APC. This is mainly useful. When APC is statically compiled into PHP, It is disabled because there is no other method (when it is compiled into DSO, php can be used. the extension line in ini is commented out ).

Apc. shm_segments

Type: integer
The number of shared memory blocks allocated to the compilation cache. If APC runs out of shared memory and you have set apc. shm_size to the maximum value allowed by the system, you can increase the value of this parameter.

Apc. shm_size

Type: integer
The size of each shared memory block is measured in MB. By default, the size of shared memory blocks in some systems (including most BSD Variant Systems) is very low.

Apc. optimization

Type: integer
Optimization level. If it is set to 0, optimization is disabled. The higher the value, the more powerful the optimization is. We are looking forward to improvement in speed. This is experimental.

Apc. num_files_hint

Type: integer
The number of source files that are included and requested on your Web server. If you are not sure, set it to 0 or omitted. This setting may be mainly used for sites with thousands of source files.

Apc. ttl

Type: integer
When a cache entry is required by another entry in the cache area, we need to consider the number of seconds that the cache entry can be idle in the cache area. Setting this parameter to 0 means that your cache may be filled with fresh entries, and new entries cannot be cached.

Apc. gc_ttl

Type: integer
The number of seconds that a cache entry will survive in the garbage collection list. This value provides error protection when executing a cache source file while the server process is dead. If the source file is modified, the cache entries allocated to the old version of the memory will not be recycled until the TTL value set by this parameter reaches. Setting 0 is to disable this feature.

Apc. cache_by_default

Type: Boolean
The default value is On, but it can be set to Off and used with apc. filters starting with the plus sign. The file is cached only when the filter is matched.

Apc. filters

Type: String
A list of POSIX extension Regular Expressions separated by commas. If any Mode matches the source file name, the file will not be cached. Note that the file name used for matching is the file name passed to include/require, rather than the absolute path. If the first character of the regular expression is +, the expression means that any file that matches the expression will be cached. If the first character is-, no matching will be cached. -Is the default value, so it can be omitted.

Apc. mmap_file_mask

Type: String
If you use-enable-mmap (enabled by default) to compile MMAP support for APC, the value here is the mktemp file mask passed to the mmap module (Recommended Value: "/tmp/apc. XXXXXX "). This mask is used to determine whether the memory ing area is file-backed or shared memory backed. For direct file-backed memory ing, set it to "/tmp/apc. XXXXXX" (exactly 6 X ). To use the POSIX shm_open/mmap style, you must set it to "/apc. shm. XXXXXX. You can also set it to "/dev/zero" to use the "/dev/zero" interface of the kernel for the memory mapped anonymously. If this command is not defined, anonymous ing is mandatory.


Apc. slam_defense

Type: integer
On a very busy server, whether you start the service or modify files, you will cause a multi-process to try to cache the competition for the same file at the same time. This option sets the percentage of files that the process skips and tries to cache. Or you can think of this as the probability that a separate process will skip the cache. For example, setting apc. slam_defense to 75 means that the process has a 75% chance of not caching files that are not cached. Therefore, the higher the setting, the more likely the cache collision rate can be reduced. If it is set to 0, this feature is disabled.

Apc. file_update_protection

Type: integer
When you modify a file on a running server, you should perform atomic operations. That is, first write a temporary file, and then rename the file (mv) to its final location. Many text editors, cp, tar, and other similar programs do not perform this operation. This means that you have the opportunity to access (cache) the file while it is still being written. The apc. file_update_protection setting causes the cache to mark the delay of new files. The default value is 2, which means that the file will not be cached if the modification time of the file is less than 2 seconds from the Access time. Unfortunately, users who access half of the files they write will see a strange situation, but at least this is not continuous. If you are sure that you often use atomic operations to update your files, you can disable this protection by setting this parameter to 0. If your system is full of io operations and it takes more than 2 seconds to update the program, you may need to increase the value.

Apc. enable-cli

Type: integer
Mostly for testing and debugging. Enable the APC function for PHP in the CLI version. In general, you will not expect to create, port, or discard the APC cache for each CLI request, but it is easy to enable APC for the CLI version in various test cases.


Case:
Apc. enabled = 1
Apc. shm_segments = 1
Apc. shm_size = 64
Apc. optimization = 0
Apc. num_files_hint = 1000
Apc. ttl = 0
Apc. gc_ttl = 3600
Apc. cache_by_default = On
Apc. slam_defense = 0
Apc. file_update_protection = 2
Apc. enable_cli = 0
Apc. stat = 0

2. APC cache case

 


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.