Previously using PHP4 with FastCGI I was using eAccelerator as my PHP opcode / bytecode accelerator as APC was too unstable causing several crashes a week. However since upgrading to PHP 5.2.5 using ISAPI I have migrated across to APC and to date have found it to be very stable. So I thought it about time that I cover the topic of installing APC into your PHP environment for IIS, which is what we'll cover in this article.
Download APC
APC is not included in the standard Windows package for PHP, but it is included in the PECL binaries package which can be downloaded from the PHP site. One word of caution is that APC is not stable when using PHP on IIS using Microsoft's new FastCGI handler due to the memory management within APC itself, so in this article we'll be expressly talking about using APC on IIS when PHP is configured using the ISAPI module. Also be aware that using PHP on IIS in ISAPI mode does restrict you to what PECL extensions you can use as not all of them are thread safe.
Enable APC
Before we enable the APC extension, first make sure you have correctly set your extension_dir value in php.ini. This setting tells PHP where to look for the PECL extensions when loading. With php.ini open you add the following line to the list of enabled extensions;
extension=php_apc.dll
As covered in my previous how to guide on Enabling PHP PECL extensions for Windows, you will notice that the only difference between an enabled an disabled PECL extension is that the semicolon is removed from in front of the enabled ones.
Configure APC
At last count there were 26 APC configuration directives, so rather than go through them all I just through the ones that generally need alteration over the default values in an IIS environment. To specify your APC directives in php.ini, you should first create a titled section called [APC] and then set your directives in the format of directive=value. For example;
apc.shm_size=64MAs mentioned there are many other APC directives which I have not included as they are either not relevant to using PHP on IIS, their default values are fine or I from my testing I suspect them of causing instability in the PHP environment.
Restart IIS & Verify
That should be it for configuring APC, now all you should have to do is restart IIS to make the changes effective. You can verify APC is loaded using the phpinfo function by placing the following code in a file with a php extension in your website root and accessing it with your web browser;
<?php
phpinfo();
?>Even better is if you goto the APC page on the PECL website and download the source. Amongst the source files you'll find a file called apc.php which is a script that provides some very useful stats and functions for APC. Simply place this script somewhere on your website (preferably secure) so you can then use it to keep an eye on things.
Hopefully this guide is enough to get you going with an opcode / bytecode accelerator for PHP on IIS, as it really is one of if not the biggest single performance increase you'll get. As always feel free to leave a comment or post in the forums if you wish to leave any feedback.
Comments
APC and PHPMyAdmin
APC seems to stop PHPMyAdmin from working. Do you recommend a workaround?
I have struck this problem
I have struck this problem too. I've yet to investigate why this is and for the moment am disabling APC just for phpMyAdmin using per directory values for my PHP config.
----------------
Dominic Ryan
3 x Microsoft IIS MVP, MCSE, MCSA
IIS Aid owner/webmaster