PHP skills: application APC cache optimization PHP program

Source: Internet
Author: User
AlternativePHPCache (APC) is a free and openly optimized PHP code cache. It is used to provide free, open, and robust architectures to cache and optimize intermediate PHP code.

Alternative PHP Cache (APC) is a free and openly optimized PHP code Cache. It is used to provide free, open, and robust architectures to cache and optimize intermediate PHP code.

In Windows, the APC request contains the c: \ tmp directory, which must be writable to the Web server process.

1. installation:

Install it in PHP extension.

2. configuration

Apc. enabled boolean
Apc. optimization
Options can be changed in the script

Apc php. ini configuration options
[APC]
; Alternative PHP Cache for caching and optimizing PHP intermediate code

Apc. cache_by_default = On
; SYS
Whether to enable caching for all files by default.
If it is set to Off and used together with the apc. filters command starting with the plus sign, the file is cached only when the filter is matched.

Apc. enable_cli = Off
; SYS
Whether to enable APC for the CLI version. This command is only available 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 action.

Apc. file_update_protection = 2
; SYS
When you modify a file on a running server, you should perform atomic control.
That is, first write a temporary file, and then rename the file (mv) to the ultimate name.
The text editor and cp, tar and other programs are not controlled in this way, resulting in the possibility of buffering incomplete files.
The default value is 2. when visiting files, if the time interval between invention and modification is less than 2 seconds, no buffer is provided.
The unfortunate visitor may get incomplete content, but this bad effect will not be extended by caching.
If you can ensure that all Update control is atomic control, you can use 0 to close this feature.
If your system is slow to update due to a large number of IO controls, you need to increase this value.

Apc. filters =
; SYS
; A list of expanded regular expressions separated by commas.
If the source file name matches any mode, the file is not cached.
Note that the file name used for matching is the file name passed to include/require, rather than the correct path.
If the first character of the regular expression is '', it means that any file matching the expression will be cached,
If the first character is '-', no match will be cached. '-' Is the default value and can be omitted.

Apc. ttl = 0
; SYS
The number of seconds that cache entries will stay in the buffer. 0 never times out. Recommended value: 7200 ~ 36000.
If it is set to 0, 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 ~ for each user ~ 36000.
If it is set to 0, 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 that cache entries can exist in the garbage collection table.
This value provides a security measure, even if a server process crashes when the cached source file is executed,
And the source file has been corrected, and the memory for the old duty configuration will not be recycled until the TTL value is reached.

If it is set to zero, this feature is disabled.


Apc. include_once_override = Off
; SYS
; Keep it Off. otherwise, unexpected results may occur.

Apc. max_file_size = 1 M
; SYS
; Files larger than this size cannot be cached.

Apc. mmap_file_mask =
; SYS
If the application-enable-mmap (enabled by default) has compiled MMAP support for APC,
The value here is the file mask of the mktemp style passed to the mmap module (the recommended value is '/tmp/apc. xxxxxx ').
The 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 apply the POSIX shm_open/mmap style, you must set it to '/apc. shm. xxxx.
You can also set it to '/dev/0' to the'/dev/0' interface of the memory application kernel mapped anonymously.
If this command is not defined, the application is forced to perform anonymous ING.

Apc. num_files_hint = 1000
; SYS
The approximate number of different source files that may be contained or begged on the Web server (recommended value: 1024 ~ 4096 ).
If you cannot determine, set it to 0. this setting is important for websites with thousands of source files.

Apc. optimization = 0
; Optimization level (recommended value: 0 ).
The positive integer value indicates that the optimizer is enabled. the higher the value, the more radical the application is optimized.
A higher value may have a very limited speed of promotion, but it is still in the experiment.

Apc. report_autofilter = Off
; SYS
; Whether to record all scripts that are not actively cached due to early/late binding.

Apc. shm_segments = 1
; SYS
; The number of shared memory blocks allocated to the compiler buffer (recommended value: 1 ).
If APC consumes shared memory and the apc. shm_size command is set to the maximum value promised by the system,
; You can try to increase this value.

Apc. shm_size = 30
; SYS
; The size of each shared memory block (in MB, recommended value: 128 ~ 256 ).
Some systems (including most BSD variants) have very few default shared memory blocks.

Apc. slam_defense = 0
; SYS (against the application of this command, we recommend that you use the apc. write_lock command)
On a very busy server, whether it is a startup service or a correction file,
; It is possible that multiple processes intend to cache a file at the same time, leading to competition conditions.
This command is used to set the percentage of cached steps skipped when processing files that are not cached.
For example, if the value is set to 75, the cache is not cached when files are not cached. this reduces the chance of collision.
We recommend that you set it to 0 to disable this feature.

Apc. stat = On
; SYS
; Whether to enable the script update check.
Be cautious when changing the command value.
The default value On indicates that the APC checks whether the script is updated every time the script is requested,
If updated, the compiled content is automatically re-compiled and cached. However, this has a negative impact on performance.
If it is set to Off, the performance is not checked, which greatly improves the performance.
To make the updated content take effect, you must restart the Web server.
This command is also valid for include/require files. But note that,
If you are using a relative path, APC must check each include/require operation to locate the file.

 

The check can be skipped when the application does its best, so you are encouraged to perform include/require control on the path.


Apc. user_entries_hint = 100
; SYS
; Similar to the num_files_hint command, only for different users.
If you cannot determine, set it to 0.

Apc. write_lock = On
; SYS
Whether to enable the write lock.
On a very busy server, whether it is a startup service or a correction file,
; It is possible that multiple processes intend to cache a file at the same time, leading to competition conditions.
; Enable this command to avoid the presentation of competition conditions.

Apc. rfc1867 = Off
; SYS
After this command is enabled, for each Upload file that contains the APC_UPLOAD_PROGRESS field just before the file field,
APC will create an upload _ User cache entry (that is, the value of the APC_UPLOAD_PROGRESS field ).

3. 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. there are only a few functions, as listed below.

Apc_cache_info () returns the cache information
Apc_clear_cache () clears the apc cache content.
By default (no parameter), only the system cache is cleared. to clear the user cache, what is required? User 'parameter.
Apc_define_constants (string key, array constants [, bool case_sensitive]) caches the array constants as constants.
Apc_load_constants (string Key ).
Retrieve constant cache.
Apc_store (string key, mixed var [, int ttl]).
Retain data in the cache.
Apc_fetch (string key ).
Obtain the cache content retained by apc_store
Apc_delete (string key ).
Delete the content retained by apc_store.

Apc governance:

Go to pecl.php.net to download the apc source package. there is an apc. php package. copy it to the location where your web server can visit. you can visit it after browsing.

Governance interface functions:
1. Refresh Data
2. View Host Stats
3. System Cache Entries
4. User Cache Entries
5. Version Check

 

 

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.