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.


ruslany on September 2nd 2009 in FastCGI, PHP

PoorFairAverageGoodExcellent (No Ratings Yet)

11 Responses to “Windows Cache Extension for PHP and CPU usage”

  1. Gravatar ImageDotNetShoutout responded on 03 Sep 2009 at 4:29 am #

    Windows Cache Extension for PHP and CPU usage – Ruslan Yakushev…

    Thank you for submitting this cool story – Trackback from DotNetShoutout…

  2. Gravatar ImageChris responded on 12 Sep 2009 at 8:19 am #

    Hi. I installed PHP 5.2 and then this one.

    Is that enough or I have to make some changes to fcgiext.ini?

    Thank you.

  3. Gravatar ImageChris responded on 12 Sep 2009 at 8:24 am #

    Also, how do I exactly know the thing is on? Is there a process in task manager?

  4. Gravatar Imageruslany responded on 12 Sep 2009 at 8:45 am #

    @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.

  5. Gravatar ImageArtigo sobre melhorar performance do PHP do IIS | Pablo Weyne - IIS - Windows - Microsoft responded on 02 Oct 2009 at 7:55 am #

  6. Gravatar ImagePHP on Windows: The WinCache 1.0 Benchmark – techPortal responded on 19 Nov 2009 at 12:14 pm #

    [...] Yakushev (our IIS contact at Microsoft who is involved with the WinCache project) actually has an article on exactly this problem; when you install WebPI with WinCache, be sure to take this into account [...]

  7. Gravatar ImageMa_Khan responded on 21 Nov 2009 at 1:14 pm #

    Hey Ruslan,

    The Wincache plugin on the right is awesome… Let me know if you can share it … :)

  8. Gravatar Imageruslany responded on 21 Nov 2009 at 2:02 pm #

    @Ma_Khan: This is not a plugin. It is just a couple of function calls in the template.

  9. Gravatar ImageHein responded on 17 Mar 2011 at 3:47 am #

    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?


  10. Gravatar Imageruslany responded on 17 Mar 2011 at 7:35 am #

    Hi Hein, yes wincache only works with FastCGI.

  11. Gravatar ImageDan responded on 21 Feb 2012 at 7:37 pm #

    IIS 7.5 handles the maxInstances dynamically by default:

Trackback URI | Comments RSS

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

XML Markup: If You want to add XML code to the comment please XML encode it first, otherwise the code will not show up.

Recently Published Articles