search
HomeBackend DevelopmentPHP TutorialAnalysis of two sets of configuration files and parameters of PHP APC

This article mainly introduces 2 sets of PHP APC configuration files and detailed parameters. Friends who need it can refer to

1. Install APC

The compilation parameters are as follows:

./configure --enable-apc --enable-apc-spinlocks --disable-apc-pthreadmutex

I won’t go into the installation process, the standard PHP extension installation mode.

2. 2 sets of configuration files

High performance, not suitable for frequent updates:

apc.enabled=1
apc.stat = 0
apc.stat_ctime = 0
apc.shm_size = 64M
apc.shm_segments = 1
apc.num_files_hint = 1000
apc.ttl = 0
apc.slam_defense = 0
apc.write_lock = 1
apc.file_update_protection = 2

Slightly lower performance:

apc.enabled=1
apc.stat = 1
apc.stat_ctime = 1
apc.shm_size = 64M
apc.shm_segments = 1
apc.num_files_hint = 1000
apc.ttl = 86400
apc.slam_defense = 0
apc.write_lock = 1
apc.file_update_protection = 2

The key to the 2 sets of configurations is apc.stat. After it is turned on, APC will not check whether the file is updated, so you can Reduce a large number of unnecessary system calls.
However, for newly released problems, PHP needs to be restarted. You can choose according to the situation.

In addition, attach a parameter description:

apc.enabled boolean
apc.enabled can be set to 0 to disable APC. It is mainly used when APC is statically compiled into PHP, because there is no other way to disable it (compiled as DSO, you can comment out the extension line in php.ini).

apc.shm_segments integer
The number of shared memory blocks to be allocated by the compiler cache. If APC runs out of shared memory but has set apc.shm_size to the maximum allowed by the system, you can try increasing this value.

apc.shm_size integer
The size of each shared memory block in MB. Some systems (including most BSD variants) have a very low shared memory block size by default.

apc.optimization integer
Optimization level. Set to 0 to disable the optimizer, higher values ​​to use more aggressive optimization. Expect very limited speed improvements. Still in testing.

apc.num_files_hint integer
A rough estimate of the number of different origin files that are included or requested on the Web server. Set to 0 or remove this option if unsure; this setting is mainly used on sites with thousands of source files.

apc.user_entries_hint integer
Similar to apc.num_files_hint, stores cache variables based on the number of unique users. If unsure, set it to 0 or remove this item.

apc.ttl integer
The number of seconds the cache entry is allowed to stay in the buffer. 0 means never times out. The recommended value is 7200~86400. Setting it to 0 means that the buffer may be filled with old cache entries, resulting in the inability to cache new entries.

apc.user_ttl integer
Similar to apc.ttl, but for each user, the recommended value is 7200~86400. Setting to 0 means that the buffer may fill up with old cache entries, preventing new entries from being cached. If greater than 0, APC will attempt to delete expired entries.

apc.gc_ttl integer
The number of seconds the cache entry can exist in the garbage collection table. This value provides a safety measure that if the file is modified while the server process is executing a cached source file, the older version will not be recycled until this TTL is reached. Set to zero to disable this feature.

apc.cache_by_default boolean
The default is on, but it can be set to off and used together with apc.filters starting with a plus sign, then the file will only be cached when matching the filter .

apc.filters string
A comma-separated list of POSIX extended regular expressions. If any of the patterns match the source file name, the file is not 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 t it means any file 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.mmap_file_mask string
If MMAP support was compiled for APC using --enable-mmap (enabled by default), the value here is the mktemp-style file passed to the mmap module 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's). 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 forces the use of anonymous mapping.

apc.slam_defense integer
On a very busy server, whether starting a service or modifying a file, a race condition may result from multiple processes trying to cache a file at the same time. This option sets the percentage at which the process skips the caching step when processing files that have not been cached. 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. Use of this directive is deprecated and is encouraged to be set to 0 to disable this feature. It is recommended to use the apc.write_lock instruction.

Deprecated by apc.write_lock.

apc.file_update_protection integer
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, 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.enable_cli integer
Whether to enable APC functionality for the CLI version, turn this option on only for testing and debugging purposes. Under normal circumstances it is not ideal to create, populate and destroy the APC cache on every request to the CLI, but it is useful in various testing scenarios to be able to easily make the CLI version of PHP APC

apc. max_file_size integer
Default is 1M, files larger than this value will not be cached.

apc.stat integer
Whether to enable script update check. Be very careful when changing this command value. The default value On indicates that APC checks whether the script has been updated each 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 is performed, resulting in significant performance improvements. But in order for the updated content to take effect, you must restart the web server (Translator's Note: If you use cgi/fcgi, you need to restart the cgi/fcgi process). On production servers where script files rarely change, significant performance improvements can be achieved by disabling this option.

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.write_lock boolean
On a busy server, when the web server is started for the first time, or many files are modified at the same time, APC may compile the same file multiple times File, write lock guarantees that only one process will attempt to compile and cache an uncached script. Other processes trying to use the script will not use the opcode cache, instead locking and waiting for the cache to be generated.

apc.report_autofilter boolean
Whether to record all scripts that are automatically not cached due to early/late binding reasons.

apc.include_once_override boolean
Optimize the include_once() and require_once() functions to avoid executing additional system calls.

apc.rfc1867 boolean
Enable monitoring file upload progress function

apc.rfc1867_prefix string
Buffering for uploading files Item entry name prefix

apc.rfc1867_name string
Hidden form item name for uploaded files that need to be processed by APC

apc.rfc1867_freq string
Update frequency of user uploaded file cache items. The value can be a percentage of the total file size, or an absolute size (case-insensitive) ending in "k", "m", or "g" kilobytes, megabytes, or gigabytes. 0 means the fastest possible update, but This may result in slower upload speeds.

apc.rfc1867_ttl bool
TTL for rfc1867 entries.

apc.localcache boolean
Use non-locking local process shadow- cache, which reduces competition between locks when writing to the buffer.

apc.localcache.size integer
The size of the local process shadow-cache, should be set to a sufficiently large value, approximately half of apc.num_files_hint.

apc.coredump_unmap boolean
Enable APC signal handler, such as SIGSEGV signal, when the signal is written to the core file. When these signals are received, APC will attempt to unmap the shared memory segment, excluding it from the core file. This setting can improve system stability when receiving a fatal signal or using APC's large shared memory segment configuration.

apc.stat_ctime integer
Verifying ctime (creation time) can avoid problems caused by SVN or rsync and ensure that the inode has not changed since the last statistics. APC usually only checks mtime (modification time).

apc.canonicalize bool
If set to on, the relative path will be changed to an absolute path in no-state mode (no checking for file updates).

apc.preload_path string
apc.use_request_time bool
Use the SAPI request start time for TTL.

apc.file_md5 bool
Record the md5 value of the file

##apc.lazy_functions integer
Enable function lazy loading

apc.lazy_classes integer
Enable class lazy loading

The above is the entire content of this article. I hope it will be helpful to everyone's study. For more related content, please pay attention to the PHP Chinese website!

Related recommendations:

3 ways to generate random numbers in PHP

Comparison of commonly used framework functions in PHP

The above is the detailed content of Analysis of two sets of configuration files and parameters of PHP APC. For more information, please follow other related articles on the PHP Chinese website!

Statement
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
How does PHP identify a user's session?How does PHP identify a user's session?May 01, 2025 am 12:23 AM

PHPidentifiesauser'ssessionusingsessioncookiesandsessionIDs.1)Whensession_start()iscalled,PHPgeneratesauniquesessionIDstoredinacookienamedPHPSESSIDontheuser'sbrowser.2)ThisIDallowsPHPtoretrievesessiondatafromtheserver.

What are some best practices for securing PHP sessions?What are some best practices for securing PHP sessions?May 01, 2025 am 12:22 AM

The security of PHP sessions can be achieved through the following measures: 1. Use session_regenerate_id() to regenerate the session ID when the user logs in or is an important operation. 2. Encrypt the transmission session ID through the HTTPS protocol. 3. Use session_save_path() to specify the secure directory to store session data and set permissions correctly.

Where are PHP session files stored by default?Where are PHP session files stored by default?May 01, 2025 am 12:15 AM

PHPsessionfilesarestoredinthedirectoryspecifiedbysession.save_path,typically/tmponUnix-likesystemsorC:\Windows\TemponWindows.Tocustomizethis:1)Usesession_save_path()tosetacustomdirectory,ensuringit'swritable;2)Verifythecustomdirectoryexistsandiswrita

How do you retrieve data from a PHP session?How do you retrieve data from a PHP session?May 01, 2025 am 12:11 AM

ToretrievedatafromaPHPsession,startthesessionwithsession_start()andaccessvariablesinthe$_SESSIONarray.Forexample:1)Startthesession:session_start().2)Retrievedata:$username=$_SESSION['username'];echo"Welcome,".$username;.Sessionsareserver-si

How can you use sessions to implement a shopping cart?How can you use sessions to implement a shopping cart?May 01, 2025 am 12:10 AM

The steps to build an efficient shopping cart system using sessions include: 1) Understand the definition and function of the session. The session is a server-side storage mechanism used to maintain user status across requests; 2) Implement basic session management, such as adding products to the shopping cart; 3) Expand to advanced usage, supporting product quantity management and deletion; 4) Optimize performance and security, by persisting session data and using secure session identifiers.

How do you create and use an interface in PHP?How do you create and use an interface in PHP?Apr 30, 2025 pm 03:40 PM

The article explains how to create, implement, and use interfaces in PHP, focusing on their benefits for code organization and maintainability.

What is the difference between crypt() and password_hash()?What is the difference between crypt() and password_hash()?Apr 30, 2025 pm 03:39 PM

The article discusses the differences between crypt() and password_hash() in PHP for password hashing, focusing on their implementation, security, and suitability for modern web applications.

How can you prevent Cross-Site Scripting (XSS) in PHP?How can you prevent Cross-Site Scripting (XSS) in PHP?Apr 30, 2025 pm 03:38 PM

Article discusses preventing Cross-Site Scripting (XSS) in PHP through input validation, output encoding, and using tools like OWASP ESAPI and HTML Purifier.

See all articles

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

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool