Revision #5 has been created by François Gannaz on Mar 7, 2012, 12:48:45 PM with the memo:
Reorder APC settings and split them in two categories
« previous (#4) next (#9) »
Changes
Title
unchanged
Getting the Most out of APC for Yii
Category
unchanged
How-tos
Yii version
unchanged
Tags
unchanged
caching, apc
Content
changed
[...]
=================
If you have several Yii-based applications running on one server, you might want to consider dropping one copy of the Yii framework (i.e. the content of the `framework` folder in the release tarball) into `/usr/local/share/yii` and let the [`include_path`](http://php.net/manual/ini.core.php#ini.include-path) configuration setting point to that. APC will only have to pick up one copy of Yii then. In the process, you'll also conserve a bit of disk space.
APC Settings
============
APC can be fine-tuned by a number of settings. Just toss them into your `apc.ini`, restart your webserver (or php-fpm process) and see the magic happening. I found tThe following options
to beare the most important
for Yii:
- [`apc.enabled`](http://php.net/manual/apc.configuration.php#ini.apc.enabled)
Self explaining. This option enables or disables APC alltogether. Be advised that this is a system-wide setting, soyou cannot selectively switch APC on or off for e.g. certain directories via a `.htaccess` or `.user.ini` file.
You'll want this to be set to **on**
.
- [`apc.cache_by_default, which is the default value.
- [`apc.shm_size`](http://php.net/manual/apc.configuration.php#ini.apc.
cache-by-default) Controls the default caching behaviour of APC. This can be used together with `apc.filters` for complex cache setups. But in most cases, you'll wanshm-size) The size of the cache. Take note that is the size of the opcode **and** the user cache. Currently, APC does not allow you to specify seperate memory segments for these. As a general rule: Do not set this lower than 16MB and monitor APC's memory usage closely. If you set this to
o be **1**.
- [`apc.mmap_file_mask`](http://php.net/manual/apc.configuration.php#ini.apc.mmap-file-mask)
Filemask for the shared memory mechanism. The best setting I could find has been **/dev/shm/apc.XXXXXX**low, APC's memory might suffer heavy fragmentation, which will result in a high performance penalty.
Monitor your APC activity (see the following section) and set a value where APC's memory isn't too fragmented (generally at least 32 MB).
- [`apc.stat`](http://php.net/manual/apc.configuration.php#ini.apc.stat) Controls if APC should check for modified files on every request. This setting will bring you the greatest speed benefit. Set it to **0** on production servers but to **1** in development environments (otherwise PHP won't pick up changes you've applied to the code). If you're rolling out a new version of your software, simply restart your webserver or FastCGI process in order to clear the opcode cache.
- [`apc.lazy_classes`](http://php.net/manual/apc.configuration.php#ini.apc.lazy-classes) and [`apc.lazy_functions`](http://php.net/manual/apc.configuration.php#ini.apc.lazy-functions) These settings are marked as _experimental_. However, I've found no regressions after using these. If you're feeling lucky and you're using anonymous functions for `evalExpression`, you may want to set these to **1**.
- [`apc.include_once_override`](http://php.net/manual/apc.configuration.php#ini.apc.include-once-override) Setting this to on will speed up `include*` and `require*` calls. However, this setting will introduce
Other interesting parameters are:
- [`apc.cache_by_default`](http://php.net/manual/apc.configuration.php#ini.apc.cache-by-default) Controls the default cach
aing
es in the behaviour of
PHP. Yii is running fine with it but others (such as phpMyAdmin) aren't so happy. So **evaluate carefully if this doesn't break other applications on your server**. You've been warned!APC. This can be used together with `apc.filters` for complex cache setups. But in most cases, you'll want this to be **1**.
- [`apc.ttl`](http://php.net/manual/apc.configuration.php#ini.apc.ttl) Controls how long cached opcodes may be cached before being reloaded. Set this to **0** on your productions system so this will never happen. This is most useful together with `apc.stat=0`.
- [`apc.num_files_hint`](http://php.net/manual/apc.configuration.php#ini.apc.num-files-hint) This is a hint for APC to reserve sufficient space for the opcode cache. It helps APC during the initial cache build. It isn't terribly important as it's really just a hint. But while you're at it: Set it to roughly the number of your project's PHP files.
- [`apc.user_entries_hint`](http://php.net/manual/apc.configuration.php#ini.apc.user-entries-hint) Same as `apc.num_files_hint` but for user cache entries, so it is only interesting if you're using APC as a user cache, too. A too high value might result in over-provisioning memory for the cache. This is highly individual, so you'll need to evaluate this yourself.
- [`apc.
shm_sizemmap_file_mask`](http://php.net/manual/apc.configuration.php#ini.apc.
shm-size) The size of the cache. Take note that is the size of the opcode **and** the user cache. Currently, APC does not allow you to specify seperate memory segments for these. As a general rule: Do not set this lower than 16MB and monitor APC's memory usage closely. If your setting this too low, APC's memory might suffer heavy fragmentation, which will mmap-file-mask)
Filemask for the shared memory mechanism. The best setting I could find has been **/dev/shm/apc.XXXXXX**
- [`apc.lazy_classes`](http://php.net/manual/apc.configuration.php#ini.apc.lazy-classes) and [`apc.lazy_functions`](http://php.net/manual/apc.configuration.php#ini.apc.lazy-functions) These settings are marked as _experimental_. However, I've found no regressions after using these. If you're feeling lucky and you're using anonymous functions for `evalExpression`, you may want to set these to **1**.
- [`apc.include_once_override`](http://php.net/manual/apc.configuration.php#ini.apc.include-once-override) Setting this to on will speed up `include*` and `require*` calls. However, this setting will introduce changes in the behaviour of PHP. Yii is running fine with it but others (such as phpMyAdmin) aren't so happy. So **evaluate care
sful
t in a high performance penalty.ly if this doesn't break other applications on your server**. You've been warned!
Monitoring APC
--------------
Some of the aforementioned settings can be very specific to your setup and your application. So you need to take a look at what APC is doing. There are currently two ways of achieving this:[...]