Introducing PHP Tips: Optimizing PHP programs with APC cache

Source: Internet
Author: User
Tags apc posix

unconsciously came to the small series of articles, this time brought a little bit of knowledge to share with you, I hope you have something to gain! what are the programming languages

Alternative PHP cache (APC) is a free, publicly available, optimized code cache for PHP. It is used to provide free, open and robust architecture to cache and optimize PHP's intermediate code.
Under Windows, APC requires a c:\\\\tmp directory, and the directory is writable to the WEB server process.
1. Installation
Install in PHP extension form
2. Configuration
Apc.enabled Boolean
Apc.optimization optimization
Options can be changed in the script
An explanation of APC php.ini configuration options
[APC]
; Alternative PHP cache for caching and optimizing PHP intermediate code
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
; 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 direct file-backed memory mapping, set to "/TMP/APC". XXXXXX "(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. Web programming language

the description of programming language can be divided into syntax and semantics. The syntax is to illustrate which symbols or words are combined in a programming language, and semantics is the interpretation of programming. Some languages are defined by specification files, such as the C language specification file, which is also part of the ISO standard, 2011 years later, ISO/IEC 9,899:2011, while other languages (like Perl) have a major programming language implementation file that is considered a reference implementation. [1]
programming language commonly known as "computer language", the variety is very much, in general, can be divided into machine language, assembly language, high-level language three categories. Computer every action, a step, is in accordance with the computer language has been programmed to execute, the program is the computer to execute the set of instructions, and the program is all in the language we have mastered to write. So people have to control the computer. Be sure to issue commands to the computer through computer language. There are two types of programming languages available today: assembly language and high-level languages. [1]
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 using 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).
3. Functions
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 use of APC is relatively simple, with only a few functions, listed below.
Apc_cache_info () returns cache information
Apc_clear_cache () clears APC cache content.
By default (no parameters), only the system cache is cleared, to clear the user cache, the ' user ' parameter is required.
Apc_define_constants (string key, array constants [, BOOL Case_sensitive]) adds the array constants to the cache with constants.
Apc_load_constants (String Key).
Remove the constant cache.
Apc_store (string key, mixed var [, int ttl]).
Save the data in the cache.
Apc_fetch (string key).
Get cached content Saved by Apc_store
Apc_delete (string key).
Delete Apc_store saved content.
Management of APC:
To pecl.php.net download the APC source package there is a apc.php,copy where your Web server can access it and browse to it.
The management interface features are:
1. Refresh Data
2. View Host Stats
3. System Cache Entries
4. User Cache Entries
5. Version Check

C Language Programming

If you feel a lot of harvest, then please go to class home official website together into the knowledge of heaven!


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