Home Backend Development PHP Tutorial In-depth analysis of php apc_PHP tutorial

In-depth analysis of php apc_PHP tutorial

Jul 21, 2016 pm 03:10 PM
apc php definition open supply yes go deep of Target cache free parse

apc definition: apc is an open and free php opcode cache. Its goal is to provide a free, open and sound framework for caching and optimizing PHP intermediate code.
APC common functions:
1.apc_clear_cache() Clear the apc cache content
2.apc_define_constants(string key,array constants,[,bool case_sensitive]) Add array constants as constants Cache
3.apc_load_constants(string key) Get the constant cache
4.apc_store(string key,mixed var [, int ttl]) Save data in the cache
5.apc_fetch(string key) Get apc_store to save Cache data
6.apc_delete(string key) Delete the content saved by apc_store
7.apc_add(string key,mixd var [, int ttl]) Cache a variable to the data store (only if the variable has not been stored before case)
8.apc_exists(mix keys) Check whether one or more apc key names exist
9.apc_delete_file(mixed keys) Delete the cache of the given file from the opcode cache
10.apc_compile_file (string filename [,bool atmic=true]) Bypass the restrictions of filters, cache files
11.apc_cache_info (string cache_type [,bool limited=false]) Get the cache i-type milkshake
Note: apc_clear_cache only clears opcode cache file, apc_delete clears the variables in the cache; for predefined variables, you can use the apc_define_constants function; for PHP variables, you can use the function apc_store. It is better to use apc than memcache, and does not need to go through the network transmission protocol tcp; apc is not suitable for passing the function apc_store Caching frequently changing user data will cause some strange phenomena; APC itself does not support distribution.
Common apc configuration:
1. How much memory will be allocated to apc, ini option apc.shm_size (integer) controls this setting. The default is 30M
2. Whether to check file modifications each time apc is requested. The ini option apc.stat controls this setting. The default value is 1, which means that each time a script is requested, the production script will be updated. If updated, it will be automatically recompiled. and caching compiled content have a proportional impact on performance, so this is set to 0
3. Cache fewer scripts through ini option apc.filters
apc advantages:
1. Use the spinlocks (spin) lock mechanism to achieve the best performance
2. apc provides apc.php for monitoring and managing apc cache. (Note: Change the administrator name and password)
3.apc creates shared memory through mmap anonymous mapping by default, and cache objects are stored in this large memory space. The shared memory is managed by apc itself
4. Adjust the values ​​of apc.shm_size, apc.num_files_hints, and apc.user_entires_hint to the best
5.php predefined constants, you can use the apc _define——constants() function. However, apc developers say that pecl hidef has better performance, abandon define, it is inefficient
6.apc_store, for PHP variables such as system settings, the life cycle is the entire application (from httpd daemon to httpd daemon shutdown), use apc is better than memcache. (No need to go through network transmission protocol)
7.apc is not suitable for caching frequently changed user data through the function apc_store(), and some strange phenomena will occur.
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) }
?>
Supplementary detailed configuration instructions:
apc.cache_by_default = on
;sys
; Whether to enable buffering for all files by default.
; If set to off and used with the apc.filters directive starting with a plus sign, files will only be cached if they match the filter.

apc.enable_cli = off
;sys
; Whether to enable apc function for cli version, this instruction is only turned on 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 way.

apc.file_update_protection = 2
;sys
; When you modify files on a running server, you should perform atomic operations.
; That is, first write to a temporary file, and then rename (mv) the file to the final name.
; Text editors and programs such as cp and tar do not operate in this way, resulting in the possibility of buffering incomplete files.
; The default value 2 means that when accessing a file, if the modification time is found to be less than 2 seconds from the access time, no buffering will be performed.
; The unlucky visitor may get corrupted content, but the bad effect is not magnified by caching.
; If you can ensure that all update operations are atomic operations, you can turn off this feature with 0.
; If your system updates slowly due to a large number of IO operations, you need to increase this value.

apc.filters =
;sys
; A comma-separated list of POSIX extended regular expressions.
; If the source file name matches any of the patterns, the file will not be cached.
; Note that the file name 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 any file matching the expression will be cached,
; If the first character is "-" then any matches will not is cached. "-" is the default value and can be omitted.

apc.ttl = 0
;sys
; The number of seconds a cache entry is allowed to stay in the buffer. 0 means never times out. The recommended value is 7200~36000.
; Setting to 0 means that the buffer may be filled with old cache entries, preventing new entries from being cached.

apc.user_ttl = 0
;sys
; Similar to apc.ttl, but for each user, the recommended value is 7200~36000.
; Setting to 0 means that the buffer may be filled with old cache entries, preventing new entries from being cached.

apc.gc_ttl = 3600
;sys
; The number of seconds that cache entries can exist in the garbage collection table.
; This value provides a safety measure, even if a server process crashes while executing a cached source file,
; and the source file has been modified, the memory allocated for the old version will not be reclaimed until Until this ttl value is reached.
; Set to zero to disable this feature.

apc.include_once_override = off
;sys
; There is currently no documentation for this command, see: http://pecl.php.net/bugs/bug.php?id=8754
; Please keep it off, otherwise it may cause unexpected results.

apc.max_file_size = 1m
;sys
; Prohibits files larger than this size from being cached.

apc.mmap_file_mask =
;sys
; If mmap support is compiled for apc using –enable-mmap (enabled by default),
; the value here is the mktemp passed to the mmap module Style file mask (recommended value is "/tmp/apc.xxxxxx").
; This mask is used to determine whether the memory mapped area should be file-backed or shared memory backed.
; For direct file-backed memory mapping, set it to look like "/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 it to "/dev/zero" to use the kernel's "/dev/zero" interface for anonymously mapped memory.
; Not defining this directive means forcing the use of anonymous mapping.

apc.num_files_hint = 1000
;sys
; The approximate number of different source files that may be included or requested on the web server (recommended value is 1024~4096).
; If you are not sure, set to 0; this setting is mainly used for sites with thousands of source files.

apc.optimization = 0
; Optimization level (recommended value is 0).
; A positive integer value indicates that the optimizer is enabled, with higher values ​​using more aggressive optimization.
; Higher values ​​may have very limited speed improvements, but are currently experimental.

apc.report_autofilter = off
;sys
; Whether to record 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 (recommended value is 1).
; If apc has exhausted shared memory and the apc.shm_size directive has been set to the maximum value allowed by the system,
; you can try increasing 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 (It is against the use of this command, it is recommended to use the apc.write_lock command)
; On a very busy server, whether starting a service or modifying a file,
; may cause a race condition due to multiple processes trying to cache a file at the same time.
; This directive is used to set the percentage of the process that skips the caching step when processing uncached files.
; For example, setting it to 75 means that there is a 75% probability of not caching when an uncached file is encountered, thereby reducing the chance of collision.
; It is encouraged to set to 0 to disable this feature.

apc.stat = on
;sys
; Whether to enable script update check.
; Be very careful when changing this command value.
; The default value on means that apc checks whether the script has been updated every time it is requested.
; If it is updated, it will automatically recompile and cache the compiled content. However, doing so has a negative impact on performance.
; If set to off, no checking will be performed, thus greatly improving performance.
; But in order for the updated content to take effect, you must restart the web server.
; This directive is also valid for include/require files. But it should be noted that
; if you use a relative path, apc must check to locate the file every time include/require.
; Using absolute paths can skip the check, so you are encouraged to use absolute paths for include/require operations.

apc.user_entries_hint = 100
;sys
; Similar to the num_files_hint directive, but for each different user.
; Set to 0 if you are not sure.

apc.write_lock = on
;sys
; Whether to enable write lock.
; On a very busy server, whether starting a service or modifying a file,
; may cause a race condition due to multiple processes trying to cache a file at the same time.
; Enabling this directive can avoid race conditions.

apc.rfc1867 = off
;sys
; After turning on this command, for each uploaded file that contains the apc_upload_progress field just before the file field,
; apc will automatically create a The user cache entry of upload_ (that is, the apc_upload_progress field value).

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/327153.htmlTechArticleapc definition: apc is an open and free php opcode cache. Its goal is to provide a free, open and sound framework for caching and optimizing PHP intermediate code. Commonly used functions in apc: 1...
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1672
14
PHP Tutorial
1277
29
C# Tutorial
1257
24
PHP: A Key Language for Web Development PHP: A Key Language for Web Development Apr 13, 2025 am 12:08 AM

PHP is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7

PHP and Python: Comparing Two Popular Programming Languages PHP and Python: Comparing Two Popular Programming Languages Apr 14, 2025 am 12:13 AM

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

PHP in Action: Real-World Examples and Applications PHP in Action: Real-World Examples and Applications Apr 14, 2025 am 12:19 AM

PHP is widely used in e-commerce, content management systems and API development. 1) E-commerce: used for shopping cart function and payment processing. 2) Content management system: used for dynamic content generation and user management. 3) API development: used for RESTful API development and API security. Through performance optimization and best practices, the efficiency and maintainability of PHP applications are improved.

The Enduring Relevance of PHP: Is It Still Alive? The Enduring Relevance of PHP: Is It Still Alive? Apr 14, 2025 am 12:12 AM

PHP is still dynamic and still occupies an important position in the field of modern programming. 1) PHP's simplicity and powerful community support make it widely used in web development; 2) Its flexibility and stability make it outstanding in handling web forms, database operations and file processing; 3) PHP is constantly evolving and optimizing, suitable for beginners and experienced developers.

PHP and Python: Different Paradigms Explained PHP and Python: Different Paradigms Explained Apr 18, 2025 am 12:26 AM

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP vs. Other Languages: A Comparison PHP vs. Other Languages: A Comparison Apr 13, 2025 am 12:19 AM

PHP is suitable for web development, especially in rapid development and processing dynamic content, but is not good at data science and enterprise-level applications. Compared with Python, PHP has more advantages in web development, but is not as good as Python in the field of data science; compared with Java, PHP performs worse in enterprise-level applications, but is more flexible in web development; compared with JavaScript, PHP is more concise in back-end development, but is not as good as JavaScript in front-end development.

PHP and Python: Code Examples and Comparison PHP and Python: Code Examples and Comparison Apr 15, 2025 am 12:07 AM

PHP and Python have their own advantages and disadvantages, and the choice depends on project needs and personal preferences. 1.PHP is suitable for rapid development and maintenance of large-scale web applications. 2. Python dominates the field of data science and machine learning.

PHP: Handling Databases and Server-Side Logic PHP: Handling Databases and Server-Side Logic Apr 15, 2025 am 12:15 AM

PHP uses MySQLi and PDO extensions to interact in database operations and server-side logic processing, and processes server-side logic through functions such as session management. 1) Use MySQLi or PDO to connect to the database and execute SQL queries. 2) Handle HTTP requests and user status through session management and other functions. 3) Use transactions to ensure the atomicity of database operations. 4) Prevent SQL injection, use exception handling and closing connections for debugging. 5) Optimize performance through indexing and cache, write highly readable code and perform error handling.

See all articles