Home Backend Development PHP Tutorial Introducing PHP Tips: Using APC Cache to Optimize PHP Programs

Introducing PHP Tips: Using APC Cache to Optimize PHP Programs

Jul 25, 2016 am 08:46 AM

Unknowingly, I came to the editor's article again. This time I brought a little knowledge to share with you. I hope you can gain something! What are the programming languages ​​

Alternative PHP Cache (APC) is a free and public optimized code cache for PHP. It is used to provide a free, open and robust framework for caching and optimizing PHP intermediate code.
Under Windows, APC requires the c:\\tmp directory to be writable by the web server process.
1. Installation
Install as PHP extension
2. Configuration
apc.enabled boolean
apc.optimization optimization
Options can be changed in script
Detailed explanation of APC PHP.ini configuration options
[APC]
; Alternative PHP Cache is used to cache and optimize PHP intermediate code
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 functionality for CLI builds, turn this directive on for testing and debugging purposes only.
apc.enabled = On
; Whether to enable APC, if APC is statically compiled into PHP and 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 amplified by caching.
; If you can ensure that all update operations are atomic, you can turn off this feature with 0.
; If your system updates slowly due to heavy IO operations, you may 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 is not cached.
; Note that the file name used for matching is the file name passed to include/require, not the absolute path.
; If the first character of the regular expression is "+" it means that any files matching the expression will be cached,
; If the first character is "-" then any matches will not be 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 fill up 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 fill up with old cache entries, preventing new entries from being cached.
apc.gc_ttl = 3600
;SYS
; The number of seconds a cache entry 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 this TTL value is reached.
; Set to zero to disable this feature.
apc.include_once_override = Off
;SYS
; Please keep it Off, otherwise it may cause unexpected results.
apc.max_file_size = 1M
;SYS
; Prevent 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-style file mask passed to the mmap module (the 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 "/tmp/apc.XXXXXX" (exactly 6 X's).
; To use POSIX-style shm_open/mmap, it needs to be set to "/apc.shm.XXXXXX".
; You can also set to "/dev/zero" to use the kernel's "/dev/zero" interface for anonymously mapped memory.
; Not defining this directive forces the use of anonymous mapping. Web programming language

The description of a programming language can generally be divided into syntax and semantics. Grammar is the correct combination of symbols or words in a programming language, and semantics is the explanation of programming. Some languages ​​are defined by specification documents. For example, the C language specification document is also part of the ISO standard. The version after 2011 is ISO/IEC 9899:2011, while other languages ​​(like Perl) have a main programming language implementation document. , considered as a reference implementation. [1]
Programming languages ​​are commonly known as "computer languages" and there are many types. Generally speaking, they can be divided into three categories: machine language, assembly language, and high-level language. Every action or step taken by the computer is executed according to a program that has been programmed in computer language. A program is a collection of instructions for the computer to execute, and all programs are written in the language we master. Therefore, if people want to control the computer, they must issue commands to the computer through computer language. Currently, there are two common forms of programming languages: assembly language and high-level language. [1]
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 useful for sites with thousands of source files.
apc.optimization = 0
; Optimization level (recommended value is 0).
; A positive integer value enables the optimizer, with higher values ​​using more aggressive optimizations.
; 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 runs out of shared memory and the apc.shm_size directive has been set to the maximum 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,
; can 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 at which the process 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.
; Encouraged to be set to 0 to disable this feature.
apc.stat = On
;SYS
; Whether to enable script update checking.
; Be very careful when changing this directive value.
; The default value On means that APC checks whether the script has been updated every time it is requested,
; Automatically recompile and cache the compiled content if updated. However, doing so has a negative impact on performance.
; If set to Off, no checking is 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 relative paths, APC must check to locate the file on every 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,
; can cause a race condition due to multiple processes trying to cache a file at the same time.
; Enable this directive to avoid race conditions.
apc.rfc1867 = Off
;SYS
; After turning on this directive, for each uploaded file that contains the APC_UPLOAD_PROGRESS field just before the file field,
; APC will automatically create a user cache entry for upload_ (that is, the APC_UPLOAD_PROGRESS field value).
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, with only a few functions, listed below.
apc_cache_info () returns cache information
apc_clear_cache() clears the 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]) Add array constants to the cache as constants.
apc_load_constants (string Key).
Remove the constant cache.
apc_store ( string key, mixed var [, int ttl] ).
Save data in cache.
apc_fetch(string key).
Get the cache content saved by apc_store
apc_delete ( string key ).
Delete the content saved by apc_store.
apc management:
Go to pecl.php.net to download the apc source code package. There is apc.php, copy it to a place where your web server can access it, and browse to access it.
Management interface functions include:
1. Refresh Data
2. View Host Stats
3. System Cache Entries
4. User Cache Entries
5. Version Check

C language programming

If you feel that you have gained a lot, then please go to the Lesson Home official website and enter the paradise of knowledge together!




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 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
1663
14
PHP Tutorial
1266
29
C# Tutorial
1239
24
Explain different error types in PHP (Notice, Warning, Fatal Error, Parse Error). Explain different error types in PHP (Notice, Warning, Fatal Error, Parse Error). Apr 08, 2025 am 12:03 AM

There are four main error types in PHP: 1.Notice: the slightest, will not interrupt the program, such as accessing undefined variables; 2. Warning: serious than Notice, will not terminate the program, such as containing no files; 3. FatalError: the most serious, will terminate the program, such as calling no function; 4. ParseError: syntax error, will prevent the program from being executed, such as forgetting to add the end tag.

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.

Explain secure password hashing in PHP (e.g., password_hash, password_verify). Why not use MD5 or SHA1? Explain secure password hashing in PHP (e.g., password_hash, password_verify). Why not use MD5 or SHA1? Apr 17, 2025 am 12:06 AM

In PHP, password_hash and password_verify functions should be used to implement secure password hashing, and MD5 or SHA1 should not be used. 1) password_hash generates a hash containing salt values ​​to enhance security. 2) Password_verify verify password and ensure security by comparing hash values. 3) MD5 and SHA1 are vulnerable and lack salt values, and are not suitable for modern password security.

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.

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

What are HTTP request methods (GET, POST, PUT, DELETE, etc.) and when should each be used? What are HTTP request methods (GET, POST, PUT, DELETE, etc.) and when should each be used? Apr 09, 2025 am 12:09 AM

HTTP request methods include GET, POST, PUT and DELETE, which are used to obtain, submit, update and delete resources respectively. 1. The GET method is used to obtain resources and is suitable for read operations. 2. The POST method is used to submit data and is often used to create new resources. 3. The PUT method is used to update resources and is suitable for complete updates. 4. The DELETE method is used to delete resources and is suitable for deletion operations.

Explain the difference between self::, parent::, and static:: in PHP OOP. Explain the difference between self::, parent::, and static:: in PHP OOP. Apr 09, 2025 am 12:04 AM

In PHPOOP, self:: refers to the current class, parent:: refers to the parent class, static:: is used for late static binding. 1.self:: is used for static method and constant calls, but does not support late static binding. 2.parent:: is used for subclasses to call parent class methods, and private methods cannot be accessed. 3.static:: supports late static binding, suitable for inheritance and polymorphism, but may affect the readability of the code.

How does PHP handle file uploads securely? How does PHP handle file uploads securely? Apr 10, 2025 am 09:37 AM

PHP handles file uploads through the $\_FILES variable. The methods to ensure security include: 1. Check upload errors, 2. Verify file type and size, 3. Prevent file overwriting, 4. Move files to a permanent storage location.

See all articles