Windows Cache Extension for PHP and CPU usage

The FastCGI module in IIS has a configuration setting maxInstances, which controls the number of concurrently running php-cgi.exe processes that IIS creates to process PHP requests. To achieve optimal performance, it is recommended to fine tune this setting for your specific environment starting with 8-10 instances per CPU core (e.g. maxInstances=32 for quad-core CPU).

The Windows Cache Extension for PHP can be used to improve performance of PHP applications running on Windows operating systems. The extension caches the compiled PHP opcode in the shared memory, which helps to avoid re-doing of such CPU intensive operations as parsing and compiling of the PHP source code. This means that when Windows Cache Extension for PHP is enabled, less CPU cycles are required for a web server to process PHP requests. Because of that, the previously configured value for the FastCGI maxInstances setting may not be adequate to load the server’s CPU completely and it may be necessary to increase the value further.

To increase the maxInstances value on IIS 7 run this command from an elevated command line prompt:

appcmd.exe set config  -section:system.webServer/fastCgi /[fullPath='C:\PHP\php-cgi.exe',arguments=''].maxInstances:"32"  /commit:apphost

Note: replace the fullPath with the path to php-cgi.exe on your server.

Alternatively you can just edit the <fastCGI> section the applicationHost.config file located at C:\Windows\System32\inetsrv\config\ folder:

  <application fullPath="C:\PHP\php-cgi.exe" maxInstances="32">
  <!-- Some other settings may go here-->

To increate the maxInstances value on IIS 5.1 and IIS 6.0 run this command:

>cscript C:\windows\system32\inetsrv\fcgiconfig.js -set -section:"PHP" –MaxInstances:32

Note: replace the section name if necessary.

Alternatively you can edit the fcgiext.ini file located at C:\Windows\System32\inetsrv\ folder:

;some other settings may go here

When you measure the performance of the Windows Cache Extension for PHP, make sure to monitor the CPU usage. If you see that CPU is not fully utilized try increasing the FastCGI maxInstances setting and you may be able to get better performance results.

11 thoughts on “Windows Cache Extension for PHP and CPU usage”

  1. Pingback: DotNetShoutout
  2. @Chris: you will need to edit php.ini file to enable the extension (if you used Web Platform Installer, then the extension should have been already enabled). Follow the instructions in the documentation to enable the extension and check that it works.

  3. Hi Rus,

    We are running a 6core server setup so that would add up to 48 instances for FastCGI.

    Not really detecting a significant speed improvement. Do you need to install wincache AND FastCGI to get a real speed boost for php dynamic pages?


Leave a Reply

Your email address will not be published. Required fields are marked *