PHP on IIS: MonitorChangesTo setting in FastCGI

PHP on Windows loads its configuration file php.ini during the startup of the process php-cgi.exe. When PHP is run on IIS via FastCGI the php-cgi.exe processes are re-used to handle many requests. If configuration settings in php.ini file get updated, those changes will not be picked up by php-cgi.exe processes until the processes are recycled or restarted by IIS FastCGI module. This means that any time you change the PHP configuration you have to manually recycle IIS Application Pools that use PHP. This post explains how to configure FastCGI in IIS so that PHP configuration changes take effect right away without the need to manually recycle or restart the IIS Application Pools.

The latest releases of the FastCGI Extensoin 1.5 and FastCGI update for IIS 7.0 have a new configuration setting monitorChangesTo that takes an absolute path to a file that FastCGI will monitor for changes. In case of PHP this means that you can set monitorChangesTo to a path to php.ini file, so that any time it is modified the FastCGI module will restart the php-cgi.exe to pick up the configuration changes.

Assuming that the PHP configuration file location is C:\PHP\php.ini, the instructions below describe how to use monitorChangesTo on different IIS versions:

IIS 5.1 and IIS 6.0

The FasCGI configuration is stored in a file %windir%\system32\inetsrv\fcgiext.ini. You can manually update it to use monitorChangesTo:

[Types]
php=PHP

[PHP]
ExePath=C:\PHP\php-cgi.exe
MonitorChangesTo=C:\PHP\php.ini

Alternatively you can use the configuration helper script %windir%\system32\inetsrv\fcgiconfig.js :

cscript %windir%\system32\inetsrv\fcgiconfig.js -set -section:PHP -MonitorChangesTo:C:\PHP\php.ini

IIS 7.0

You will need to install the FastCGI Update in order to be able to use monitorChangesTo in IIS 7.0 on Windows Vista and Windows Server 2008.

To configure this setting, use the command below:

%windir%appcmd.exe set config -section:system.webServer/fastCgi ^
/[fullPath='C:\PHP\php-cgi.exe',arguments=''].monitorChangesTo:"C:\PHP\php.ini" ^
/commit:apphost

IIS 7.5

In Windows 7 and Windows Server 2008 R2 you can use the same appcmd command as described above or you can use IIS Manager user interface for FastCGI settings:

Technical Notes

Below are the technical details that you need to be aware of when using this new feature in FastCGI module:

  • The file that monitorChangesTo is pointing to must exist on a file system. If it does not exist then FastCGI module will generate an error;
  • If the file is located on a network share then FastCGI module cannot use Windows file change notifications so it will switch to polling and will check the file for changes every 5 seconds;
  • If a relative file path is specified instead of an absolute path then FastCGI will assume that it is relative to the location of php-cgi.exe file.

13,835 views

ruslany on March 30th 2010 in FastCGI, PHP

PoorFairAverageGoodExcellent (6 votes, average: 3.67 out of 5)

2 Responses to “PHP on IIS: MonitorChangesTo setting in FastCGI”

  1. Gravatar ImageInvertir en bolsa responded on 12 Oct 2011 at 9:02 am #

    I’m following all the steps explained in this post, and when I restart IIS the pages appears in blank. Any suggestions? I’m using ISS 7.5. Thank you.

  2. Gravatar ImageFanda responded on 19 Apr 2012 at 2:22 am #

    Great article. Thank you. I there something like that for ISAPI?

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