http://docs.moodle.org/en/Installing_APC_in_Windows
Contents |
APC (Alternative PHP Cache) is a PHP opcode cache. It stores PHP pages in RAM and reduces hard disk activity. This makes a real difference to the performance in Moodle, and you should be able to achieve a 50% increase in system capacity and your CPU will be 50% less busy.
This guide is for installation of APC on a Windows server. The instructions have been tested on a Windows 2003 server, and they should also be applicable if you are using Windows XP as a test server.
Warning: You cannot install APC and Zend Optimiser on the same server. You should choose one or the other.
Follow these steps to install APC.
Download the windows binary for the PHP version you have installed from http://pecl4win.php.net/ext.php/php_apc.dll. Save into the PHP extensions folder, which is c:\php\ext by default.
Note: Make sure you choose the right extension for your version (branch) of PHP.
Edit the php.ini file and add the following line in the extensions section:
extension = php_apc.dll
Check that this has worked by restarting your web server and looking at the output of phpinfo from the Moodle administration screens or from a text file containing this line:
<?php phpinfo(); ?>
To check the amount of memory that is available for APC to use:
<?php print_r(apc_sma_info()); ?>
... [avail_mem] => 31447368 ...
The total amount of memory used by the cache is given by this formula:
total_memory = apc.shm_segments * apc.shm_size
In this example, the available memory is approx 32Mb. Usually if we need more than 32Mb in our cache, we should increase the number of segments that APC uses. However, this is can cause web server faults, so it is best to increase the segment size instead.
When setting the total memory available for the cache, start with the lowest that a single Moodle install can work with (64Mb). This amount may not be enough if you have extra modules and blocks installed, so check by monitoring the cache regularly in the first two weeks that your server is running. Look at the monitoring section below and gradually increase your total cache memory until there is no more cache churn.
The default APC settings are as follows:
apc.cache_by_default = On apc.enable_cli = Off apc.enabled = On apc.file_update_protection = 2 apc.filters = apc.gc_ttl = 3600 apc.include_once_override = Off apc.max_file_size = 1M apc.num_files_hint = 1000 apc.optimization = Off apc.report_autofilter = Off apc.shm_segments = 1 apc.shm_size = 30 apc.slam_defense = 0 apc.stat = On apc.ttl = 0 apc.user_entries_hint = 100 apc.user_ttl = 0 apc.write_lock = On
For a full explanation of these settings, see http://www.php.net/apc.
For a general Moodle installation several changes are needed. These are:
Note that to disable APC temporarily set apc.enabled = 0 in PHP.INI and restart your webserver.
A working APC section of of PHP.INI is shown below, so copy and paste the following at the end of your PHP.INI file:
[APC] apc.enabled = 1 apc.shm_segments = 1 apc.shm_size = 64 apc.max_file_size = 10M apc.stat=1
The remainder of the settings can be left as their default.
APC needs a temporary directory to save its files. It will attempt to save the files in the windows temp directory, so set the C:\WINDOWS\TEMP directory to be writable by the web server user (for IIS this is IUSR_machine-name, for Apache no change to permissions are necessary), e.g. at least Read & Execute permissions.
The APC source contains a php script that is useful for monitoring and tuning the performance of your cache.
Note: Once you have successfully installed APC, move this file to a password protected area for security.
To tune the cache, look at the General Cache Information and Detailed Memory Usage and Fragmentation sections. Watch the Cache Full Count and Fragmentation % indicators.
To confirm that there has been an improvement in performance, try the following:
c:\apache2\bin>ab.exe -n 50 -c 1 -d http://mymoodle.com/moodle/index.php
To uninstall APC, add a semicolon to the extension line in your PHP.INI as follows:
;extension = php_apc.dll
Remember to restart your web server.