In-depth analysis of PHP apc_php tutorials

Source: Internet
Author: User
Tags apc posix
APC Definition: APC is an open and free php opcode cache. Its goal is to provide a free, open and robust framework for caching and optimizing PHP intermediate code.
APC Common functions:
1.apc_clear_cache () Clear APC cache content
2.apc_define_constants (String Key,array constants,[,bool case_sensitive]) adds the array constants to the cache with constants
3.apc_load_constants (String key) takes out the constant cache
4.apc_store (String key,mixed var [, int TTL]) saves data in cache
5.apc_fetch (string key) gets Apc_store saved cache data
6.apc_delete (string key) to delete Apc_store saved content
7.apc_add (String key,mixd var [, int TTL]) caches a variable to the data store (only if it is not stored before the variable)
8.apc_exists (Mix keys) checks if there is one or more APC key names present
9.apc_delete_file (mixed keys) removes the cache of a given file from the opcode cache
10.apc_compile_file (string filename [, bool Atmic=true]) bypasses the limitations of filters, caches files
11.apc_cache_info (String cache_type [, bool Limited=false]) Get cache I-type milkshake
Note: Apc_clear_cache only clears the opcode cache file, Apc_delete clearly the variables in the cache, predefined variables, you can use the Apc_define_constants function, PHP variables can use the function Apc_store, Using APC is better than memcache and does not need to go through the Network transport protocol TCP;APC does not apply to the user data that is frequently changed by the function Apc_store cache, there are some strange phenomena; The APC itself does not support distribution.
APC Common configuration:
1. How much memory will be assigned to the Apc,ini option Apc.shm_size (integer) to control this setting. Default is 30M
2. Each request for APC Check file modification, INI option Apc.stat Control This setting, the default value is 1, indicating that every time the script is requested to reduce the output of the script is updated, if the update automatically recompile and cache the compiled content, the performance has a proportional impact, so this set to 0
3. Cache fewer scripts with the INI option apc.filters
APC Advantages:
1. Use the spinlocks (spin) lock mechanism to achieve optimal performance
The 2.APC provides apc.php for monitoring and managing the APC cache. (Note: Modify the administrator name and password)
3.APC By default, the shared memory is created by Mmap Anonymous mappings, and the cache objects are stored in this large memory space. The shared memory is managed by APC itself
4. Adjust the value of Apc.shm_size, Apc.num_files_hints, Apc.user_entires_hint to the best
5.php pre-defined constants, you can use the APC _define--constants () function. However, APC developers say PECL HiDef performance is more, abandon define, it is inefficient
6.apc_store, for PHP variables such as system settings, the life cycle is the entire application (from the httpd daemon to the httpd daemon shutdown), and APC is better than memcache. (No Network Transfer Protocol required)
7.APC does not apply to frequently changing user data through the function Apc_store () cache, there are some strange phenomena.
Example:
$constants = Array (' apc_file ' = ' apc.php ', ' AUTHOR ' = ' tim ');
Apc_define_constants (' Memb ', $constants);
Apc_load_constants (' memb ');
Echo apc_file;
Echo AUTHOR;

if (!apc_fetch (' time1 ')) apc_store (' Time1 ', Time ());
if (!apc_fetch (' time2 ')) apc_store (' Time2 ', Time (), 2);
echo apc_fetch (' time1 ');
echo apc_fetch (' time2 ');

Class a{
Public Function B () {echo ' Success ';}
}
Apc_store (' obj ', new A ());
$a = apc_fetch (' obj ');
$a-B ();

$ret = apc_exists (Array (' foo ', ' donotexist ', ' Bar '));
Array (2) {["foo"]=> bool (true) ["Bar"]=> bool (TRUE)}
?>
additional detailed configuration instructions:
Apc.cache_by_default = On
; sys
; Whether buffering is enabled by default for all files.
; If set to off and used with the apc.filters instruction that starts with a plus sign, the file is cached only when matching the filter.

APC.ENABLE_CLI = Off
; sys
; Whether APC functionality is enabled for the CLI version, which is only opened for testing and debugging purposes.

apc.enabled = On
; If APC is enabled, it is the only option if APC is statically compiled into PHP and wants to disable it.

Apc.file_update_protection = 2
; sys
; 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 the final name.
; The text editor, as well as the CP, tar and other programs do not operate this way, resulting in the possibility of buffering the mutilated files.
; The default value of 2 indicates that the modification time is not buffered if the access time is less than 2 seconds when the file is accessed.
; The unfortunate visitor may get incomplete content, but the bad effect is not amplified by the cache.
; If you can ensure that all update operations are atomic, you can turn this feature off 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 a regular expression is "+" it means that any file matching the expression is cached.
; If the first character is "-" none of the matches will be cached. "-" is the default value and can be omitted.

Apc.ttl = 0
; sys
; The number of seconds that the cache entry is allowed to stay in the buffer. 0 means never time out. The recommended value is 7200~36000.
; A setting of 0 means that the buffer may be filled with old cache entries, causing the new entries to be cached.

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, causing the new entries to be cached.

Apc.gc_ttl = 3600
; sys
; The number of seconds that a 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 file.
; And the source file has been modified, and the memory allocated for the old version is not recycled until this TTL value is reached.
; Set to zero disables this attribute.

Apc.include_once_override = Off
; sys
; There is no documentation for this directive, see: http://pecl.php.net/bugs/bug.php?id=8754
; Please remain off, otherwise it may result in unexpected results.

Apc.max_file_size = 1m
; sys
; Prohibit files larger than this size from being cached.

Apc.mmap_file_mask =
; sys
; If you have compiled MMAP support for APC using –ENABLE-MMAP (enabled by default),
; The value here is the Mktemp-style file mask that is passed to the Mmap module (the recommended value is "/tmp/apc.xxxxxx").
; This mask is used to determine if the memory-mapped area is to be file-backed or shared memory backed.
; For a direct file-backed memory map, set the "/tmp/apc.xxxxxx" Look (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 memory that is mapped anonymously.
; Undefined this directive means that anonymous mappings are enforced.

Apc.num_files_hint = 1000
; sys
; Approximate number of different source files that may be included or requested on the Web server (recommended value is 1024~4096).
; If you are unsure, set to 0; This setting is primarily 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 the optimization is used.
; Higher values may have a very limited speed boost, but are still being tested.

Apc.report_autofilter = Off
; sys
; Whether to log all scripts that are not cached automatically because of the early/late binding reason.

Apc.shm_segments = 1
; sys
; The number of shared memory blocks allocated for the compiler buffer (recommended value is 1).
; If the APC runs out of shared memory and the apc.shm_size instruction is set to the maximum allowable value for the system,
; You can try to increase this value.

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

Apc.slam_defense = 0
; sys (against the use of the directive, it is recommended to use the Apc.write_lock Directive)
; On a very busy server, whether it's starting a service or modifying a file,
; Can cause a race condition because multiple processes are attempting to cache a file at the same time.
; This instruction is used to set the percentage of the process that skips cache steps when processing files that are not cached.
; For example, set to 75 indicates that there is a 75% probability of not caching when a file is not cached, thus reducing the chance of collisions.
; Encourage set to zero to disable this feature.

Apc.stat = On
; sys
; Whether to enable the script update check.
; Be very careful to change this command value.
; The default value on indicates that APC checks that 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, no check is made, resulting in a significant performance gain.
; However, in order for the updated content to take effect, you must restart the Web server.
; This command is also valid for Include/require files. But it's important to note that
; If you are using a relative path, APC must check each time 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, only for each different user.
; If you are not sure, set to 0.

Apc.write_lock = On
; sys
; Whether write locks are enabled.
; On a very busy server, whether it's starting a service or modifying a file,
; Can cause a race condition because multiple processes are attempting to cache a 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 exactly before the file field,
; APC will automatically create a Upload_ user cache entry (that is, the Apc_upload_progress field value).

http://www.bkjia.com/PHPjc/327153.html www.bkjia.com true http://www.bkjia.com/PHPjc/327153.html techarticle APC Definition: APC is an open and free php opcode cache. Its goal is to provide a free, open and robust framework for caching and optimizing PHP intermediate code. APC Common functions: 1 ...

  • 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.