Apc caching. APC in PHP: Concept, installation, use of APC. Enable APC support in Magento


APC is an abbreviation for Alternative PHP Caching. Russian text is an alternative PHP cacher. What is it used for? Like other popular cachers such as XCache and eAccelerator, it is used to increase the speed of PHP scripts. If you have your own server and are concerned about the performance of PHP scripts, then APC may be the solution to your problem. In today's article we will learn more about APC, learn how to install and test it, and use APC caching when writing PHP scripts.

What is the APC accelerator?

AcceleratorAPC(Alternative PHP Cache) is a free and open opcode cacher for PHP. It was designed to be a free, open and stable framework for caching and optimizing PHP source code. APC is in its development stage. Currently supports PHP 4 and PHP 5, including 5.3. Presumably it will be included in the standard PHP core version 6.
How is work speed achieved?PHP?
When there is a delay in loading your site, the question arises - Why? The fact is that when performing a standard call to a PHP script, it is compiled anew each time. That is, the same work is done several times. If it's a small project, the slowdowns may be minor, even invisible. But if you have a large project (website), then you have noticed that when accessing there is a delay in loading the page, despite the fact that the site is well optimized in terms of html compression and css compression. For clarity, let's see how a standard request is executed without using PHP accelerators:

At the same time executions are in progress code compilation on every request. This takes a lot of time to process the request, and therefore slows down. To get around this, accelerators were invented, of which APC is a representative. They cache the compiled code on disk, which, when accessed, prints the result. This increases the speed of PHP. APC can operate in two modes, which are configured in the file /etc/php.d/apc.ini, variable apc.stat. The variable can take values ​​1 and 0 (apc.stat=0 or apc.stat=1). When using the apc.stat=1 mode, the scripts work somewhat slower as they check for file modification, but this avoids problems when the code is changed, but the output of the result remains the same. Therefore, I advise you to set the value of the variable to 1.
After installing the APC accelerator, the request execution scheme will be as follows:

Installing an APC accelerator

Since updated versions are added to apt very late. Therefore, we will install APC via PECL:

Sudo apt-get remove --purge php-apc sudo apt-get install libpcre3-dev sudo pecl install apc
During installation we set the following configuration (YMMV):
Enable internal debugging in APC : no support Enable per request file info about files used from the APC cache : no Enable spin locks (EXPERIMENTAL) : no Enable memory protection (EXPERIMENTAL) : no Enable pthread mutexes (default) : yes Enable pthread read / write locks (EXPERIMENTAL) : no Now you need to enable APC in the settings, because... this is not done automatically. For this we create apc.ini file in the appropriate directory: sudo vim /etc/php5/conf.d/apc.ini and write the following settings in this file (recommended for working with Magento) extension=apc.so apc.enabled=1 apc.shm_size=512M apc.num_files_hint=10000 apc.user_entries_hint=10000 apc.max_file_size=5M apc.stat=0 apc.optimization=0 apc.shm_segments=1 apc.enable_cli=1 apc.cache_by_default=1 apc.include_once_override=1

Enable APC support in Magento

Open the Magento configuration file: vi app/etc/local.xml and add the following code to the global section:


apc File 0 1 MAGE_ or apc database 0 1 MAGE_


Where between the “Prefix” tags a brief description of the store is indicated so that it is possible to use APC to cache several stores built on one Magento.

How to check APC operation?

First of all, you should notice that Magento PHP scripts start to work faster. Use Firebug and a plugin for it, for example YSlow, to evaluate the speed of a site. You can download the Firebug extension for Firefox here. In addition, you can use the apc.php file by copying it from the APC distribution folder to the folder public of your project: sudo cp /usr/share/php/apc.php /your path to public Now you can open this file in your browser: http://yourhost.local/apc.php April 9, 2015 12:12 pm 1,889 views | no comments

What is APC?

APC is a PHP code caching system that allows you to speed up your website. PHP is a dynamic server-side scripting language that must be parsed, compiled, and executed on the server every time a page is requested. However, in many cases, requests are repeated, and therefore the cloud server has to re-process each of them.

In this case, APC, or Alternative PHP Cache, comes to the rescue. This tool stores PHP code in operating memory and retrieves it when needed. Essentially, it bypasses code processing and compilation, minimizing the load on the server.

This guide will demonstrate the installation and configuration of APC.

Note: To complete the guide, you must first have root privileges, as well as .

Installing APC

Before installing the APC cache, you need to install some of its dependencies. To do this, use the following command:

sudo apt-get install php-pear php5-dev make libpcre3-dev

You can then install APC using the pecl command:

sudo pecl install apc

To complete the installation, you need to edit the php.ini file:

adding the following line at the end:

extension=apc.so

Save and close the file, and then restart Apache:

sudo service apache2 restart

To find out if APC is enabled, open the PHP info page. If there is none, create an empty php file in the /var/www folder:

nano /var/www/info.php

And add this code into it:

phpinfo();
?>

Save and close the file, and then open your browser. All information about the current PHP installation will appear on the screen. If APC is enabled, the page will indicate this. In general, it is not recommended to leave this file, as it may provide access to sensitive data to unauthorized users. Remove it after checking.

Setting up APC

After installation, the APC cache starts with default settings. There are two very important settings in its configurations. So, open the php.ini file:

sudo nano /etc/php5/apache2/php.ini

Under the previously added line that includes APC, add the following line:

apc.shm_size = 64

This will allocate 64MB of RAM for APC caching. Depending on the requirements or limitations of the virtual private server, this value may vary.

Below you need to add one more line:

The apc.stat setting checks the script on every request to check for changes. If it has been changed, it will recompile it and cache the new version. This is standard APC behavior. A value of 0 on this line will tell APC not to check the script for changes. This improves performance, but there is a downside: if there are changes in the PHP script, they will not be made until the cloud server is restarted. Therefore, setting the value to 0 is recommended only on sites that are in production.

Now that the APC cache is installed and running, you can check its status and performance. Find the apc.php file in the /usr/share/php/ folder and move it to a folder accessible by the browser - for example, www.

The behavior of these functions depends on the settings in php.ini.

Although the default APC settings are suitable for most installations, some applications may require more fine-tuning.

When configuring APC, there are two main points to pay attention to. The first is how much memory to make available to the APC, and the second is whether the APC will check whether the file has been modified on each request. These settings are controlled by the parameters apc.shm_size And apc.stat, respectively. Please read the sections related to setting these parameters very carefully.

Once the server is started, the script apc.php, supplied with this extension, must be copied to the "docroot" and the rights to it must allow it to be launched through the browser. This script provides detailed information on how APC works. If GD is enabled in PHP, then this script will also show useful graphs. Of course, the first thing that will be interesting is whether APC caches anything. If APC is running, then the value Cache full count(left) will show how many times the cache has become completely full and has been forced to forcefully remove entries that were not last accessed apc.ttl seconds The lower this number, the better configured the cache is. If this number is constantly growing, then APC has to constantly clean up old entries and the whole point of caching is lost. The best way to reduce this number is to add memory to the APC. If this cannot be done, then you need to reconfigure apc.filters to limit the set of cached scripts.

If the APC is built with mmap (Memory Mapping) support, it will use only one memory segment; if, on the contrary, the APC is built with SHM (SysV Shared Memory) support, it will use several segments. MMAP has no maximum limit, unlike SHM which is limited /proc/sys/kernel/shmmax. It is generally recommended to use MMAP because it allocates memory much faster when the web server is restarted, which affects the server startup speed.

APC Configuration Parameters
Name Default Location of change List of changes
apc.enabled "1" PHP_INI_SYSTEM PHP_INI_SYSTEM in APC 2. PHP_INI_ALL in APC<= 3.0.12.
apc.shm_segments "1" PHP_INI_SYSTEM
apc.shm_size "32M" PHP_INI_SYSTEM
apc.shm_strings_buffer "4M" PHP_INI_SYSTEM Available with APC 3.1.4.
apc.optimization "0" PHP_INI_ALL PHP_INI_SYSTEM in APC 2. Removed in APC 3.0.13.
apc.num_files_hint "1000" PHP_INI_SYSTEM
apc.user_entries_hint "4096" PHP_INI_SYSTEM Available with APC 3.0.0.
apc.ttl "0" PHP_INI_SYSTEM Available with APC 3.0.0.
apc.user_ttl "0" PHP_INI_SYSTEM Available with APC 3.0.0.
apc.gc_ttl "3600" PHP_INI_SYSTEM
apc.cache_by_default "1" PHP_INI_ALL PHP_INI_SYSTEM in APC<= 3.0.12. Доступно с APC 3.0.0.
apc.filters NULL PHP_INI_SYSTEM
apc.mmap_file_mask NULL PHP_INI_SYSTEM
apc.slam_defense "1" PHP_INI_SYSTEM Available with APC 3.0.0. Before APC 3.1.4, default value "0" (disabled).
apc.file_update_protection "2" PHP_INI_SYSTEM Available with APC 3.0.6.
apc.enable_cli "0" PHP_INI_SYSTEM Available with APC 3.0.7.
apc.max_file_size "1M" PHP_INI_SYSTEM Available with APC 3.0.7.
apc.use_request_time "1" PHP_INI_ALL Available with APC 3.1.3.
apc.stat "1" PHP_INI_SYSTEM Available with APC 3.0.10.
apc.write_lock "1" PHP_INI_SYSTEM Available with APC 3.0.11.
apc.report_autofilter "0" PHP_INI_SYSTEM Available with APC 3.0.11.
apc.serializer "default" PHP_INI_SYSTEM Available with APC 3.1.0.
apc.include_once_override "0" PHP_INI_SYSTEM Available with APC 3.0.12.
apc.rfc1867 "0" PHP_INI_SYSTEM Available with APC 3.0.13.
apc.rfc1867_prefix "upload_" PHP_INI_SYSTEM
apc.rfc1867_name "APC_UPLOAD_PROGRESS" PHP_INI_SYSTEM
apc.rfc1867_freq "0" PHP_INI_SYSTEM
apc.rfc1867_ttl "3600" PHP_INI_SYSTEM Available with APC 3.1.1.
apc.localcache "0" PHP_INI_SYSTEM
apc.localcache.size "512" PHP_INI_SYSTEM Available in APC 3.0.14 - 3.1.11.
apc.coredump_unmap "0" PHP_INI_SYSTEM Available with APC 3.0.16.
apc.stat_ctime "0" PHP_INI_SYSTEM Available with APC 3.0.13.
apc.preload_path NULL PHP_INI_SYSTEM Available with APC 3.1.1.
apc.file_md5 "0" PHP_INI_SYSTEM Available with APC 3.1.1.
apc.canonicalize "1" PHP_INI_SYSTEM Available with APC 3.1.1.
apc.lazy_functions 0 PHP_INI_SYSTEM Available with APC 3.1.3.
apc.lazy_classes 0 PHP_INI_SYSTEM Available with APC 3.1.3.
For a detailed description of the PHP_INI_* constants, see the section Where Configuration Options Can Be Set.

A brief explanation of configuration directives.

If you install apc.enabled set to 0, APC will not be enabled. This is useful when APC is statically enabled in PHP and there are no other options to disable its use. If APC is built as DSO, you can simply comment out the line extension V php.ini.

Apc.shm_segments integer

The number of shared memory segments allocated for the cache. If APC has used all available shared memory and apc.shm_size as large as the system allows, increasing this parameter may help.

Apc.shm_size string

The size of a shared memory segment, specified in short notation (see this FAQ). By default, some systems (including most BSD variants) limit this value to an extremely small value.

Apc.shm_strings_buffer string

The amount of memory allocated to the shared string cache used by internal APC processes. The size must be terminated with an M or G suffix to indicate megabytes and gigabytes, respectively. Using this option can reduce the memory footprint of PHP-FPM worker processes, since the same strings will only be stored in memory once and can be used by all worker processes.

Apc.optimization integer

Optimization level. Zero disables optimization. The higher this value, the more aggressive optimization will be used. Don't expect a big increase in speed. This is experimental functionality.

Apc.num_files_hint integer

A hint on the number of unique files used on your site. Set it to zero or don't specify it at all if you're not sure. This setting is useful when you have many thousands of files.

Apc.user_entries_hint integer apc.file_update_protection integer

When a file changes on the fly, it should happen in an atomic manner. That is, first it must be written to a temporary file, and then moved ( mv) to his target position. Many text editors cp, tar and others do not do this. This may result in the file being requested (and cached) while it is being written. Settings apc.file_update_protection sets the caching delay for completely new files. Default is 2 seconds. This means that if the file modification timestamp ( mtime) says that if less than 2 seconds have passed since the file was modified, it will not be cached. The unfortunate person who tries to access the half-saved file will experience strange behavior, but at least it won't last long. If all web server files are updated atomically, using methods such as rsync(which updates correctly), then this behavior can be disabled by setting this parameter to zero. If the system is I/O overloaded, some updates may take more than two seconds and this setting should be increased accordingly.

Apc.enable_cli integer

More for testing and debugging. This setting allows APC for the CLI version of PHP. In normal work, running APC, which will create, fill and destroy the cache every time you run a script in the console, will not be the best idea. But for testing and debugging purposes, you can easily enable APC for the CLI.

Apc.max_file_size integer

Does not cache files larger than the size specified by this setting. Default is 1M.

Apc.stat integer

Be careful when changing this setting. This is enabled by default, causing APC to check script files on every request to see if they have been modified. If they have been changed, they will be recompiled and cached again. If you disable this setting, then APC will not perform such a check, and if the file has already been cached and then changed, then the new version will not get into the cache. Recaching will require restarting the web server. Please note that web servers configured to use FastCGI may not clear the cache when restarted. In industrial environments where file changes occur very rarely, disabling this option can significantly improve performance.

For files loaded via included/required, this option works great, but keep in mind that if you include a file in a relative path (on Unix, any path not starting with /), APC will check for uniqueness. If absolute paths are used, APC will skip this check and use the absolute path as the unique file identifier.

Apc.write_lock boolean

On heavily loaded servers, when the server starts up, or when many files are modified at the same time, APC may attempt to compile and cache the same file multiple times at the same time. Write locking ensures that only one process will attempt to compile and cache an uncached file. Other processes that need to use this file will use the uncached version of it, instead of waiting for it to appear in the cache.

Apc.report_autofilter boolean

Logs any scripts that were excluded from caching due to early or late linking issues.

Apc.serializer string

Tells APC to use a third-party serializer.

Apc.include_once_override boolean

Optimizes calls include_once And require_once to prevent expensive system calls.

Attention

This functionality is EXPERIMENTAL. The behavior of this directive, its name, and its documentation may change without notice in future versions of APC. Use it at your own risk.

Apc.rfc1867 boolean

The RFC1867 file download progress interceptor is only available in APC if it is built with PHP 5.2.0 or higher. If allowed, then any file uploaded to the server containing in the form, before the file field, a field with the name APC_UPLOAD_PROGRESS, will force APC to automatically create a custom cache entry like upload_ key, Where key is the field value APC_UPLOAD_PROGRESS.

Remember that the hidden field APC_UPLOAD_PROGRESS must go to the field with the file, otherwise the work will be incorrect.

Please note that file download tracking is not thread-safe, so if during the first download there is a new one with the same key, tracking of the first one will be stopped.

note that rate will only be available when all current downloads have completed.

Example #1 Example of using apc.rfc1867

print_r (apc_fetch ( "upload_ $_POST [ APC_UPLOAD_PROGRESS ] " ));
?>

The result of running this example will be something like this:

Array ( => 1142543 => 1142543 => 1828068.8 => test => file => /tmp/php8F => 0 => 1)

Apc.rfc1867_prefix string

Key prefix to use in the user cache entry created by the rfc1867 download progress tracking functionality.

Apc.rfc1867_name string

Specifies a name for a hidden form field that will enable the APC download process and specify the user cache key suffix.

Apc.rfc1867_freq string

The frequency at which the user's cache entry will be updated during a file download. It can be specified either as a percentage or by indicating the size in bytes. You can use suffixes if desired "k", "m" And "g"(case insensitive) for kilobytes, megabytes and gigabytes, respectively. If you specify zero, updates will occur as quickly as possible, but this may slow down loading times.

Apc.rfc1867_ttl integer

TTL for rfc1867 records.

Apc.localcache boolean

Enables non-blocking local process shadow caches, which reduces the amount of blocking during cache writes.

Apc.localcache.size integer

The size of the local process shadow cache should be quite large, about half of apc.num_files_hint .

Apc.coredump_unmap boolean

Enables APC to intercept signals such as SIGSEGV, which writes a coredump when issued. When these signals are received, APC will try to free all shared memory so as not to include it in the coredump. This setting can increase system stability when a critical signal has been received and the APC is configured to use a large amount of memory.

Attention

This feature is potentially dangerous. Freeing shared memory segments when a critical signal is received may result in unpredictable behavior.

Comment:

Although some kernels provide the ability to ignore some shared memory segments when writing a core file, these implementations can also ignore important memory segments such as the Apache scoreboard.

apc.stat_ctime integer

Check by ctime to avoid problems caused by programs such as svn or rsync, making sure that the inode has not changed since the last time statistics were collected. Typically APC only checks mtime.

Apc.canonicalize bool

If disabled, relative paths are converted to canonical in no-stat mode. If enabled, then files connected via the stream wrapper will not be cached, since realpath() does not support stream wrappers.

Apc.preload_path string

Optional. Specifies the path that APC uses to load cached data during startup.

Apc.use_request_time bool

Use SAPI request start time for TTL.

Apc.file_md5 bool

Write md5 hashes of files.

Apc.lazy_functions integer

Allows lazy loading of functions.

Apc.lazy_classes integer

Allows lazy loading of classes.

The configuration file is most often located in /etc/php.d/apcu.ini. Example configuration file for a server with 8 GB of RAM:

extension=apcu.so
apc.enable_cli = 1
apc.shm_segments = 1
apc.shm_size = 512M
apc.stat = 1
apc.ttl = 0
apc.user_ttl = 0
apc.max_file_size = 1M
apc.num_files_hint = 16384
apc.user_entries_hint = 16384
apc.file_update_protection=10

When using PHP 5.3, specify extension=apc.so

FastCGI note: The popular APC opcode cache for PHP cannot share a cache between PHP FastCGI processes unless PHP manages the child processes. Thus, the effectiveness of the cache is limited with mod_fcgid; concurrent PHP requests will use different opcode caches.

Description of the main APCu configuration attributes

apc.shm_segments Number of allocated memory segments. Many BSD systems have low memory segment limits. Default is 1.
apc.shm_size The size of the shared memory segment is set in megabytes. We recommend setting the minimum to 128M, for a server with 8GB - 512M, for a server with 16GB - 1024M. If multiple segments are used, the memory size must be divided by the number of segments.
apc.stat This option allows you to disable or enable APC. Value 1 - enabled, 0 - disabled.
apc.ttl PHP file caching time. When set to 0, allows the entire cache to be cleared when the allocated memory is full.
apc.user_ttl User data caching time. When set to 0, allows the entire cache to be cleared when the allocated memory is full.
apc.max_file_size The maximum size of a cached file.
apc.num_files_hint APC is used to optimize the organization of storing file data in memory. We recommend setting a value greater than 10000.
apc.user_entries_hint APC is used to optimize the organization of storing user variables in memory. We recommend setting a value greater than 10000.
apc.file_update_protection Do not cache files created less than the specified seconds ago. Allows you to avoid caching a partially written file.

Error Unable to allocate memory for pool

The include(): Unable to allocate memory for pool error occurs when memory fragmentation is severe; setting the apc.ttl and apc.user_ttl options to zero helps minimize memory fragmentation.

The behavior of these functions depends on the settings in php.ini.

Although the default APC settings are suitable for most installations, some applications may require more fine-tuning.

When configuring APC, there are two main points to pay attention to. The first is how much memory to make available to the APC, and the second is whether the APC will check whether the file has been modified on each request. These settings are controlled by the parameters apc.shm_size And apc.stat, respectively. Please read the sections related to setting these parameters very carefully.

Once the server is started, the script apc.php, supplied with this extension, must be copied to the "docroot" and the rights to it must allow it to be launched through the browser. This script provides detailed information on how APC works. If GD is enabled in PHP, then this script will also show useful graphs. Of course, the first thing that will be interesting is whether APC caches anything. If APC is running, then the value Cache full count(left) will show how many times the cache has become completely full and has been forced to forcefully remove entries that were not last accessed apc.ttl seconds The lower this number, the better configured the cache is. If this number is constantly growing, then APC has to constantly clean up old entries and the whole point of caching is lost. The best way to reduce this number is to add memory to the APC. If this cannot be done, then you need to reconfigure apc.filters to limit the set of cached scripts.

If the APC is built with mmap (Memory Mapping) support, it will use only one memory segment; if, on the contrary, the APC is built with SHM (SysV Shared Memory) support, it will use several segments. MMAP has no maximum limit, unlike SHM which is limited /proc/sys/kernel/shmmax. It is generally recommended to use MMAP because it allocates memory much faster when the web server is restarted, which affects the server startup speed.

APC Configuration Parameters
Name Default Location of change List of changes
apc.enabled "1" PHP_INI_SYSTEM PHP_INI_SYSTEM in APC 2. PHP_INI_ALL in APC<= 3.0.12.
apc.shm_segments "1" PHP_INI_SYSTEM
apc.shm_size "32M" PHP_INI_SYSTEM
apc.shm_strings_buffer "4M" PHP_INI_SYSTEM Available with APC 3.1.4.
apc.optimization "0" PHP_INI_ALL PHP_INI_SYSTEM in APC 2. Removed in APC 3.0.13.
apc.num_files_hint "1000" PHP_INI_SYSTEM
apc.user_entries_hint "4096" PHP_INI_SYSTEM Available with APC 3.0.0.
apc.ttl "0" PHP_INI_SYSTEM Available with APC 3.0.0.
apc.user_ttl "0" PHP_INI_SYSTEM Available with APC 3.0.0.
apc.gc_ttl "3600" PHP_INI_SYSTEM
apc.cache_by_default "1" PHP_INI_ALL PHP_INI_SYSTEM in APC<= 3.0.12. Доступно с APC 3.0.0.
apc.filters NULL PHP_INI_SYSTEM
apc.mmap_file_mask NULL PHP_INI_SYSTEM
apc.slam_defense "1" PHP_INI_SYSTEM Available with APC 3.0.0. Before APC 3.1.4, default value "0" (disabled).
apc.file_update_protection "2" PHP_INI_SYSTEM Available with APC 3.0.6.
apc.enable_cli "0" PHP_INI_SYSTEM Available with APC 3.0.7.
apc.max_file_size "1M" PHP_INI_SYSTEM Available with APC 3.0.7.
apc.use_request_time "1" PHP_INI_ALL Available with APC 3.1.3.
apc.stat "1" PHP_INI_SYSTEM Available with APC 3.0.10.
apc.write_lock "1" PHP_INI_SYSTEM Available with APC 3.0.11.
apc.report_autofilter "0" PHP_INI_SYSTEM Available with APC 3.0.11.
apc.serializer "default" PHP_INI_SYSTEM Available with APC 3.1.0.
apc.include_once_override "0" PHP_INI_SYSTEM Available with APC 3.0.12.
apc.rfc1867 "0" PHP_INI_SYSTEM Available with APC 3.0.13.
apc.rfc1867_prefix "upload_" PHP_INI_SYSTEM
apc.rfc1867_name "APC_UPLOAD_PROGRESS" PHP_INI_SYSTEM
apc.rfc1867_freq "0" PHP_INI_SYSTEM
apc.rfc1867_ttl "3600" PHP_INI_SYSTEM Available with APC 3.1.1.
apc.localcache "0" PHP_INI_SYSTEM
apc.localcache.size "512" PHP_INI_SYSTEM Available in APC 3.0.14 - 3.1.11.
apc.coredump_unmap "0" PHP_INI_SYSTEM Available with APC 3.0.16.
apc.stat_ctime "0" PHP_INI_SYSTEM Available with APC 3.0.13.
apc.preload_path NULL PHP_INI_SYSTEM Available with APC 3.1.1.
apc.file_md5 "0" PHP_INI_SYSTEM Available with APC 3.1.1.
apc.canonicalize "1" PHP_INI_SYSTEM Available with APC 3.1.1.
apc.lazy_functions 0 PHP_INI_SYSTEM Available with APC 3.1.3.
apc.lazy_classes 0 PHP_INI_SYSTEM Available with APC 3.1.3.
For a detailed description of the PHP_INI_* constants, see the section Where Configuration Options Can Be Set.

A brief explanation of configuration directives.

If you install apc.enabled set to 0, APC will not be enabled. This is useful when APC is statically enabled in PHP and there are no other options to disable its use. If APC is built as DSO, you can simply comment out the line extension V php.ini.

Apc.shm_segments integer

The number of shared memory segments allocated for the cache. If APC has used all available shared memory and apc.shm_size as large as the system allows, increasing this parameter may help.

Apc.shm_size string

The size of a shared memory segment, specified in short notation (see this FAQ). By default, some systems (including most BSD variants) limit this value to an extremely small value.

Apc.shm_strings_buffer string

The amount of memory allocated to the shared string cache used by internal APC processes. The size must be terminated with an M or G suffix to indicate megabytes and gigabytes, respectively. Using this option can reduce the memory footprint of PHP-FPM worker processes, since the same strings will only be stored in memory once and can be used by all worker processes.

Apc.optimization integer

Optimization level. Zero disables optimization. The higher this value, the more aggressive optimization will be used. Don't expect a big increase in speed. This is experimental functionality.

Apc.num_files_hint integer

A hint on the number of unique files used on your site. Set it to zero or don't specify it at all if you're not sure. This setting is useful when you have many thousands of files.

Apc.user_entries_hint integer apc.file_update_protection integer

When a file changes on the fly, it should happen in an atomic manner. That is, first it must be written to a temporary file, and then moved ( mv) to his target position. Many text editors cp, tar and others do not do this. This may result in the file being requested (and cached) while it is being written. Settings apc.file_update_protection sets the caching delay for completely new files. Default is 2 seconds. This means that if the file modification timestamp ( mtime) says that if less than 2 seconds have passed since the file was modified, it will not be cached. The unfortunate person who tries to access the half-saved file will experience strange behavior, but at least it won't last long. If all web server files are updated atomically, using methods such as rsync(which updates correctly), then this behavior can be disabled by setting this parameter to zero. If the system is I/O overloaded, some updates may take more than two seconds and this setting should be increased accordingly.

Apc.enable_cli integer

More for testing and debugging. This setting allows APC for the CLI version of PHP. In normal work, running APC, which will create, fill and destroy the cache every time you run a script in the console, will not be the best idea. But for testing and debugging purposes, you can easily enable APC for the CLI.

Apc.max_file_size integer

Does not cache files larger than the size specified by this setting. Default is 1M.

Apc.stat integer

Be careful when changing this setting. This is enabled by default, causing APC to check script files on every request to see if they have been modified. If they have been changed, they will be recompiled and cached again. If you disable this setting, then APC will not perform such a check, and if the file has already been cached and then changed, then the new version will not get into the cache. Recaching will require restarting the web server. Please note that web servers configured to use FastCGI may not clear the cache when restarted. In industrial environments where file changes occur very rarely, disabling this option can significantly improve performance.

For files loaded via included/required, this option works great, but keep in mind that if you include a file in a relative path (on Unix, any path not starting with /), APC will check for uniqueness. If absolute paths are used, APC will skip this check and use the absolute path as the unique file identifier.

Apc.write_lock boolean

On heavily loaded servers, when the server starts up, or when many files are modified at the same time, APC may attempt to compile and cache the same file multiple times at the same time. Write locking ensures that only one process will attempt to compile and cache an uncached file. Other processes that need to use this file will use the uncached version of it, instead of waiting for it to appear in the cache.

Apc.report_autofilter boolean

Logs any scripts that were excluded from caching due to early or late linking issues.

Apc.serializer string

Tells APC to use a third-party serializer.

Apc.include_once_override boolean

Optimizes calls include_once And require_once to prevent expensive system calls.

Attention

This functionality is EXPERIMENTAL. The behavior of this directive, its name, and its documentation may change without notice in future versions of APC. Use it at your own risk.

Apc.rfc1867 boolean

The RFC1867 file download progress interceptor is only available in APC if it is built with PHP 5.2.0 or higher. If allowed, then any file uploaded to the server containing in the form, before the file field, a field with the name APC_UPLOAD_PROGRESS, will force APC to automatically create a custom cache entry like upload_ key, Where key is the field value APC_UPLOAD_PROGRESS.

Remember that the hidden field APC_UPLOAD_PROGRESS must go to the field with the file, otherwise the work will be incorrect.

Please note that file download tracking is not thread-safe, so if during the first download there is a new one with the same key, tracking of the first one will be stopped.

note that rate will only be available when all current downloads have completed.

Example #1 Example of using apc.rfc1867

print_r (apc_fetch ( "upload_ $_POST [ APC_UPLOAD_PROGRESS ] " ));
?>

The result of running this example will be something like this:

Array ( => 1142543 => 1142543 => 1828068.8 => test => file => /tmp/php8F => 0 => 1)

Apc.rfc1867_prefix string

Key prefix to use in the user cache entry created by the rfc1867 download progress tracking functionality.

Apc.rfc1867_name string

Specifies a name for a hidden form field that will enable the APC download process and specify the user cache key suffix.

Apc.rfc1867_freq string

The frequency at which the user's cache entry will be updated during a file download. It can be specified either as a percentage or by indicating the size in bytes. You can use suffixes if desired "k", "m" And "g"(case insensitive) for kilobytes, megabytes and gigabytes, respectively. If you specify zero, updates will occur as quickly as possible, but this may slow down loading times.

Apc.rfc1867_ttl integer

TTL for rfc1867 records.

Apc.localcache boolean

Enables non-blocking local process shadow caches, which reduces the amount of blocking during cache writes.

Apc.localcache.size integer

The size of the local process shadow cache should be quite large, about half of apc.num_files_hint .

Apc.coredump_unmap boolean

Enables APC to intercept signals such as SIGSEGV, which writes a coredump when issued. When these signals are received, APC will try to free all shared memory so as not to include it in the coredump. This setting can increase system stability when a critical signal has been received and the APC is configured to use a large amount of memory.

Attention

This feature is potentially dangerous. Freeing shared memory segments when a critical signal is received may result in unpredictable behavior.

Comment:

Although some kernels provide the ability to ignore some shared memory segments when writing a core file, these implementations can also ignore important memory segments such as the Apache scoreboard.

apc.stat_ctime integer

Check by ctime to avoid problems caused by programs such as svn or rsync, making sure that the inode has not changed since the last time statistics were collected. Typically APC only checks mtime.

Apc.canonicalize bool

If disabled, relative paths are converted to canonical in no-stat mode. If enabled, then files connected via the stream wrapper will not be cached, since realpath() does not support stream wrappers.

Apc.preload_path string

Optional. Specifies the path that APC uses to load cached data during startup.

Apc.use_request_time bool

Use SAPI request start time for TTL.

Apc.file_md5 bool

Write md5 hashes of files.

Apc.lazy_functions integer

Allows lazy loading of functions.

Apc.lazy_classes integer

Allows lazy loading of classes.

10 years ago

The apc.rfc1867 example code above is a little fast and loose for those running in environments where APC RFC1867 may or may not be available. This is a little more expressive:

// if we have PHP and APC
$havePHP = (1 === version_compare (PHP_VERSION, "5.2.0" ) ? true : false );
$haveAPC = (extension_loaded ("apc" ) && 1 === version_compare (phpversion ( "apc" ), "3.0.13" ) ? true : false );
if ($havePHP && $haveAPC ) (
// if APC and upload tracking is enabled
if (ini_get ("apc.enabled" ) && ini_get ("apc.rfc1867" )) (
// get the stats
$key = ini_get ("apc.rfc1867_prefix" ) . $_REQUEST["apcid"];
$stats = apc_fetch($key);
}
}