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