Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Example Analysis of APC configuration Files and parameters in PHP

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article shares with you the content of a sample analysis of APC configuration files and parameters in PHP. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

First, install APC

Download http://pecl.php.net/get/APC-3.1.9.tgz

The compilation parameters are as follows:

The copy code is as follows:

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

Installation process aside, the standard php extension installation mode.

Two and two sets of configuration files

High performance, not suitable for frequent updates:

The copy code is as follows:

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:

The copy code is as follows:

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 configuration is apc.stat. When enabled, APC will not check whether the file is updated, which can reduce a large number of unnecessary system calls.

However, for newly released issues, you need to restart PHP. You can choose according to the situation.

In addition, attach a description of the parameters:

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 (when compiled to DSO, you can comment out the extension line in php.ini).

Apc.shm_segments integer

The compiler caches the number of blocks of shared memory to allocate. If APC runs out of shared memory but has set apc.shm_size to the maximum value allowed by the system, you can try to increase this value.

Apc.shm_size integer

The size of each shared memory block in MB. By default, some systems, including most BSD variants, have very low shared memory block sizes.

Apc.optimization integer

Optimization level. A setting of 0 disables the optimizer, while higher values use more active optimization. Expect a very limited speed increase. It's still being tested.

Apc.num_files_hint integer

A rough estimate of the number of different source files included or requested on the Web server. If you are not sure, set it to 0 or remove this setting; this setting is mainly used on sites with thousands of source files.

Apc.user_entries_hint integer

Similar to apc.num_files_hint, cache variables are stored based on the number of unique users. If you are not sure, set 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 time out. A recommended value of 7200086400 and 0 means that the buffer may be filled with old cache entries, resulting in new entries not being cached.

Apc.user_ttl integer

Similar to apc.ttl, except that for each user, the recommended value is 7200086400. A setting of 0 means that the buffer may be filled with old cache entries, so that new entries cannot be cached. If it is greater than 0, the APC will try to delete the expired entry.

Apc.gc_ttl integer

The number of seconds that cached entries can exist in the garbage collection table. This value provides a security measure that when the server process is executing the cached source file, if the file is modified, the old version will not be recycled until this TTL is reached. Set to zero to disable this property.

Apc.cache_by_default boolean

The default is on, but can be set to off and used with apc.filters starting with the plus sign, the file is cached only when the filter is matched.

Apc.filters string

A comma-separated list of POSIX extended regular expressions. If either pattern matches 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 a regular expression is + t, it means that any file that matches the expression will be cached, and if the first character is -, no matches will be cached. -it is the default value and can be omitted.

Apc.mmap_file_mask string

If you compiled MMAP support for APC with-- 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 is to be file-backed or shared memory backed. For direct file-backed memory mapping, set to "/ tmp/apc.XXXXXX" (exactly 6 Xs). 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 anonymous mapped memory. Not defining this directive means that anonymous mapping is enforced.

Apc.slam_defense integer

On very busy servers, whether starting a service or modifying a file, a race condition can be caused by multiple processes attempting to cache a file at the same time. This option sets the percentage that the process skips the caching step when processing files that are not cached. For example, setting it to 75 means there is a 75% chance that files that are not cached will not be cached, thus reducing the chance of collisions. Oppose the use of this directive and encourage it to be set to 0 to disable this feature. It is recommended to use the apc.write_lock directive.

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, write in a temporary file and then rename the file (mv) to its 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 of 2 means that when accessing the file, if it is found that the modification time is less than 2 seconds from the access time, no buffering will be made. The unfortunate visitor may get incomplete content, but the bad effect will not be magnified by caching. If you can make sure that all update operations are atomic, 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.enable_cli integer

Whether to enable the APC feature for the CLI version is turned 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 of CLI, but various test scenarios are useful and can easily make the CLI version of PHP APC

Apc.max_file_size integer

By default, files greater than this value will not be cached.

Apc.stat integer

Whether script update checking is enabled. Be very careful to change this command value. The default value of On means that APC checks to see if the script is updated every time it requests the script, and if so, automatically recompiles and caches the compiled content. However, this has a negative impact on performance. If set to Off, there is no check, resulting in a significant improvement in performance. But in order for the update to take effect, you have to restart the Web server. Script files on the production server rarely change, and you can achieve a significant performance improvement by disabling this option.

This directive is also valid for include/require files. It is important to note, however, that if you are using a relative path, APC must check each include/require to locate the file. Using absolute paths allows you to skip checking, 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, and the write lock ensures that only one process will try to compile and cache the uncached script. Other processes trying to use this script will not use the opcode cache instead of 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.

Apc.include_once_override boolean

Optimize the include_once () and require_once () functions to avoid making additional system calls.

Apc.rfc1867 boolean

Enable the function to monitor the progress of file uploads

Apc.rfc1867_prefix string

Prefix the name of the buffer entry used to upload files

Apc.rfc1867_name string

Hidden form item names of uploaded files that need to be processed by APC

Apc.rfc1867_freq string

How often the user uploads file cache entries. Values can be a percentage of the total file size, or absolute sizes ending with "k", "m", or "g" kilobytes, megabytes, or gigabytes (case insensitive). 0 means update as soon as possible, but this may slow down the upload speed.

Apc.rfc1867_ttl bool

TTL for rfc1867 entries.

Apc.localcache boolean

Using the unlocked local process shadow-cache, it reduces the 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 handles, such as SIGSEGV signals, when the signal is written to the core file. When these signals are received, APC will attempt to unmap the shared memory segment and exclude it from the core file. This setting can improve the stability of the system when receiving a fatal signal or using APC's large shared memory segment configuration.

Apc.stat_ctime integer

Verifying the ctime (creation time) avoids problems caused by SVN or rsync and ensures that the inode has not changed since the last count. APC usually only checks mtime (modification time).

Apc.canonicalize bool

If set to on, the relative path is changed to an absolute path in no-state mode (no file updates are checked).

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 delayed loading of function

Apc.lazy_classes integer

Enable class deferred loading

Thank you for reading! This is the end of this article on "sample analysis of APC configuration files and parameters in PHP". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it out for more people to see!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report