<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.technet.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>jorkeo - hosting geek : FastCGI</title><link>http://blogs.technet.com/jorke/archive/tags/FastCGI/default.aspx</link><description>Tags: FastCGI</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>FastCGI timeout on IIS7</title><link>http://blogs.technet.com/jorke/archive/2009/04/28/fastcgi-timeout-on-iis7.aspx</link><pubDate>Tue, 28 Apr 2009 06:50:00 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3232297</guid><dc:creator>jorkeo</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.technet.com/jorke/comments/3232297.aspx</comments><wfw:commentRss>http://blogs.technet.com/jorke/commentrss.aspx?PostID=3232297</wfw:commentRss><wfw:comment>http://blogs.technet.com/jorke/rsscomments.aspx?PostID=3232297</wfw:comment><description>&lt;p&gt;Had a couple of question this week around some issues that people were experiencing from long running PHP scripts that appear to timeout/hang and eventually stop/crash and is this problem with FastCGI or the application pool settings.&lt;/p&gt;  &lt;p&gt;Let’s take a look at the FastCGI settings in the ApplicationHost.config&lt;/p&gt;  &lt;p&gt;&lt;font size="2" face="Courier New"&gt;&amp;lt;fastCgi&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &amp;lt;application fullPath=&amp;quot;C:\PHP\php-cgi.exe&amp;quot; &lt;strong&gt;&lt;font color="#ff0000"&gt;activityTimeout&lt;/font&gt;&lt;/strong&gt;=&amp;quot;60&amp;quot; instanceMaxRequests=&amp;quot;10000&amp;quot;&amp;gt;      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;environmentVariables&amp;gt;      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;environmentVariable name=&amp;quot;&lt;strong&gt;&lt;font color="#ff0000"&gt;PHP_FCGI_MAX_REQUESTS&lt;/font&gt;&lt;/strong&gt;&amp;quot; value=&amp;quot;10000&amp;quot; /&amp;gt;      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;environmentVariable name=&amp;quot;&lt;font color="#ff0000"&gt;&lt;strong&gt;PHPRC&lt;/strong&gt;&lt;/font&gt;&amp;quot; value=&amp;quot;c:\php\&amp;quot; /&amp;gt;      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;/environmentVariables&amp;gt;      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &amp;lt;/application&amp;gt;      &lt;br /&gt;&amp;lt;/fastCgi&amp;gt; &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2" face="ve"&gt;You’ll the highlighted entries, the one that causes the PHP scripts to hang and stop running is &lt;strong&gt;activityTimeout&lt;/strong&gt; – simply put this value defines for FastCGI to timeout when the cgi process doesn’t talk to IIS for that amount of time specified. So if you have a script that will run longer than this, make sure you adjust it appropriately.&amp;#160; Of course, use this sensibly.&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;Couple other things highlighted are environment variables for PHP with FastCGI. &lt;strong&gt;PHP_FCGI_MAX_REQUESTS&lt;/strong&gt; governs how many requests will be processed by PHP before the PHP&amp;#160; recycling process happens. &lt;strong&gt;PHPRC&lt;/strong&gt; tells PHP where the PHP runtime configuration (php.ini) configuration file is located for this fastcgi process.&lt;/p&gt;  &lt;p&gt;- jorke&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&lt;font size="2"&gt;&amp;#160;&lt;/font&gt;&lt;/p&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3232297" width="1" height="1"&gt;</description><category domain="http://blogs.technet.com/jorke/archive/tags/Windows+Server+2008/default.aspx">Windows Server 2008</category><category domain="http://blogs.technet.com/jorke/archive/tags/IIS7/default.aspx">IIS7</category><category domain="http://blogs.technet.com/jorke/archive/tags/PHP/default.aspx">PHP</category><category domain="http://blogs.technet.com/jorke/archive/tags/FastCGI/default.aspx">FastCGI</category></item><item><title>PHP on IIS7 for Shared Hosting- AWESOME article!</title><link>http://blogs.technet.com/jorke/archive/2008/06/25/php-on-iis7-for-shared-hosting-awesome-article.aspx</link><pubDate>Wed, 25 Jun 2008 08:17:32 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3080660</guid><dc:creator>jorkeo</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.technet.com/jorke/comments/3080660.aspx</comments><wfw:commentRss>http://blogs.technet.com/jorke/commentrss.aspx?PostID=3080660</wfw:commentRss><wfw:comment>http://blogs.technet.com/jorke/rsscomments.aspx?PostID=3080660</wfw:comment><description>&lt;p&gt;check it out on &lt;a href="http://iis.net" target="_blank"&gt;IIS.NET&lt;/a&gt; - &lt;a title="http://learn.iis.net/page.aspx/208/fastcgi-with-php/" href="http://learn.iis.net/page.aspx/208/fastcgi-with-php/"&gt;http://learn.iis.net/page.aspx/208/fastcgi-with-php/&lt;/a&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;here are a couple of excerpts from the article that I strongly recommend:&lt;/p&gt;  &lt;p&gt;-----------&lt;/p&gt;  &lt;h5&gt;PHP Security Recommendations&lt;/h5&gt;  &lt;p&gt;The following recommendations describe how to tighten security of PHP in shared hosting environment. To make the recommended changes locate and open php.ini file and edit it as described below:&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;Disable remote URL's for file handling functions:      &lt;ul&gt;       &lt;li&gt;Set allow_url_fopen=Off &lt;/li&gt;        &lt;li&gt;Set allow_url_include=Off &lt;/li&gt;     &lt;/ul&gt;   &lt;/li&gt;    &lt;li&gt;Disable register_globals:      &lt;ul&gt;       &lt;li&gt;register_globals=Off &lt;/li&gt;     &lt;/ul&gt;   &lt;/li&gt;    &lt;li&gt;Restrict where PHP can read and write on a file system, e.g.:      &lt;ul&gt;       &lt;li&gt;open_basedir=&amp;quot;c:\inetpub\&amp;quot; &lt;/li&gt;     &lt;/ul&gt;   &lt;/li&gt;    &lt;li&gt;Disable safe mode:      &lt;ul&gt;       &lt;li&gt;safe_mode=Off &lt;/li&gt;        &lt;li&gt;safe_mode_gid=Off &lt;/li&gt;     &lt;/ul&gt;   &lt;/li&gt;    &lt;li&gt;Limit script execution time:      &lt;ul&gt;       &lt;li&gt;max_execution_time=30 &lt;/li&gt;        &lt;li&gt;max_input_time=60 &lt;/li&gt;     &lt;/ul&gt;   &lt;/li&gt;    &lt;li&gt;Limit memory usage and file sizes:      &lt;ul&gt;       &lt;li&gt;memory_limit=16M &lt;/li&gt;        &lt;li&gt;upload_max_filesize=2M &lt;/li&gt;        &lt;li&gt;post_max_size=8M &lt;/li&gt;        &lt;li&gt;max_input_nesting_levels=64 &lt;/li&gt;     &lt;/ul&gt;   &lt;/li&gt;    &lt;li&gt;Configure error messages and logging:      &lt;ul&gt;       &lt;li&gt;display_errors=Off &lt;/li&gt;        &lt;li&gt;log_errors=On &lt;/li&gt;        &lt;li&gt;error_log=&amp;quot;C:\path\of\your\choice&amp;quot; &lt;/li&gt;     &lt;/ul&gt;   &lt;/li&gt;    &lt;li&gt;Hide presence of PHP:      &lt;ul&gt;       &lt;li&gt;expose_php=Off &lt;/li&gt;     &lt;/ul&gt;   &lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;-----------    &lt;br /&gt;and how to ensure you can configure your own PHP.INI for each site:     &lt;br /&gt;-----------&lt;/p&gt;  &lt;h5&gt;Specifying php.ini location&lt;/h5&gt;  &lt;p&gt;When PHP process starts it determines the location of configuration php.ini file by using various settings. &lt;a href="http://www.php.net/manual/en/configuration.php"&gt;The PHP documentation&lt;/a&gt; provides detailed description of the PHP start up process. Note that one of the places where PHP process searches for php.ini location is the PHPRC environment variable. If PHP process finds a php.ini file in the path specified in this environment variable then it will use it, otherwise it will revert to default location of php.ini. This environment variable can be used to allow hosting customers to use their own versions of php.ini files.&lt;/p&gt;  &lt;p&gt;For example if there are two websites: website1 and website2; located at the following file paths: C:\WebSites\website1 and C:\WebSites\website2 then the php-cgi.exe process pools in &amp;lt;fastCgi&amp;gt; section of applicationHost.config can be configured as below:&lt;/p&gt;  &lt;p&gt;&lt;samp&gt;&amp;lt;fastCgi&amp;gt;      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &amp;lt;application fullPath=&amp;quot;C:\PHP\php-cgi.exe&amp;quot; arguments=&amp;quot;-d my.website=website1&amp;quot;&amp;gt;       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;environmentVariables&amp;gt;       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;environmentVariable name=&amp;quot;PHPRC&amp;quot; value=&amp;quot;C:\WebSites\website1&amp;quot; /&amp;gt;       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;/environmentVariables&amp;gt;       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &amp;lt;/application&amp;gt;       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &amp;lt;application fullPath=&amp;quot;C:\PHP\php-cgi.exe&amp;quot; arguments=&amp;quot;-d my.website=website2&amp;quot;&amp;gt;       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;environmentVariables&amp;gt;       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;environmentVariable name=&amp;quot;PHPRC&amp;quot; value=&amp;quot;C:\WebSites\website2&amp;quot; /&amp;gt;       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;/environmentVariables&amp;gt;       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &amp;lt;/application&amp;gt;       &lt;br /&gt;&amp;lt;/fastCgi&amp;gt;&lt;/samp&gt;&lt;/p&gt;  &lt;p&gt;This way owner of website1 can place their own version of php.ini into the C:\WebSites\website1, while the owner of website2 can use their own version of php.ini located in C:\WebSites\website2. This configuration also ensures that if there is no php.ini found in location specified by PHPRC environment variable then PHP will fall back to using the default php.ini file located in the same folder where php-cgi.exe is located.    &lt;br /&gt;-----------&lt;/p&gt;  &lt;p&gt;&lt;a href="http://learn.iis.net/page.aspx/208/fastcgi-with-php/" target="_blank"&gt;Check it out in more detail&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;- jorke&lt;/p&gt;  &lt;div class="wlWriterSmartContent" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:8918467d-4468-4c5c-83ca-9c959c5c47a8" style="padding-right: 0px; display: inline; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px"&gt;Technorati Tags: &lt;a href="http://technorati.com/tags/PHP%20on%20Windows" rel="tag"&gt;PHP on Windows&lt;/a&gt;,&lt;a href="http://technorati.com/tags/PHP" rel="tag"&gt;PHP&lt;/a&gt;,&lt;a href="http://technorati.com/tags/IIS%207" rel="tag"&gt;IIS 7&lt;/a&gt;,&lt;a href="http://technorati.com/tags/FastCGI" rel="tag"&gt;FastCGI&lt;/a&gt;,&lt;a href="http://technorati.com/tags/IIS7" rel="tag"&gt;IIS7&lt;/a&gt;&lt;/div&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3080660" width="1" height="1"&gt;</description><category domain="http://blogs.technet.com/jorke/archive/tags/IIS/default.aspx">IIS</category><category domain="http://blogs.technet.com/jorke/archive/tags/Windows+Server+2008/default.aspx">Windows Server 2008</category><category domain="http://blogs.technet.com/jorke/archive/tags/IIS7/default.aspx">IIS7</category><category domain="http://blogs.technet.com/jorke/archive/tags/PHP/default.aspx">PHP</category><category domain="http://blogs.technet.com/jorke/archive/tags/FastCGI/default.aspx">FastCGI</category><category domain="http://blogs.technet.com/jorke/archive/tags/security/default.aspx">security</category></item><item><title>HUGE performance increases with PHP on Windows 2008</title><link>http://blogs.technet.com/jorke/archive/2008/04/14/huge-performance-increases-with-php-on-windows-2008.aspx</link><pubDate>Mon, 14 Apr 2008 05:54:57 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3036323</guid><dc:creator>jorkeo</dc:creator><slash:comments>1</slash:comments><comments>http://blogs.technet.com/jorke/comments/3036323.aspx</comments><wfw:commentRss>http://blogs.technet.com/jorke/commentrss.aspx?PostID=3036323</wfw:commentRss><wfw:comment>http://blogs.technet.com/jorke/rsscomments.aspx?PostID=3036323</wfw:comment><description>&lt;p&gt;One of our local developers &lt;a href="http://www.dallasjclark.com/" target="_blank"&gt;Dallas J Clark&lt;/a&gt; (Brisbane local) blogged about an article that shows &lt;a href="http://www.dallasjclark.com/blog/?p=292" target="_blank"&gt;PHP with a 130% performance increase on Windows Server 2008&lt;/a&gt; - and of course there have been a few comments asking about the metrics of the comparison etc. So naturally I'm wading into to try and clear the water..&lt;/p&gt;  &lt;p&gt;I have to agree that there are a lot of unknowns and its difficult to do a competitive comparison with such little comparative data. What needs to be understood as that the results are for a specific case that the customer experienced, see the &lt;a href="http://cid-9720229c26829d90.skydrive.live.com/self.aspx/Public/Virtual%20Maps%20Case%20Study.pdf" target="_blank"&gt;case study right here&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;The facts&lt;/strong&gt; are that Microsoft has spent a lot of time working with &lt;a href="http://www.zend.com/en/" target="_blank"&gt;Zend&lt;/a&gt; to ensure that PHP has been engineered to run well on Windows. &lt;/p&gt;  &lt;p&gt;The key difference to understand here is that you need to understand the execution architecture differences between *nix vs Windows, respectively multi-process vs multi-threaded. As CGI is designed for multi-process execution this can give pretty ordinary performance on Windows due to the threads/cycles involved in spinning up processes every time a request is processed by the web server. Of course you could attempt multi-threading using the ISAPI filter but ask what the results were from anyone who has tried :) &amp;#8211; especially when you are not using code you have written all yourself &amp;#8211; thus the best way to ensure reliable performance on Windows is to run via CGI &amp;#8211; which of course the performance is not optimal.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Now how has this changed;&lt;/strong&gt; IIS 7 has a &lt;a href="http://www.fastcgi.com/" target="_blank"&gt;FastCGI&lt;/a&gt; module as part of its install which by its design will make anything CGI based run faster, the idea being that it allows you to process multiple requests in the one connection and once the script has been processed the &lt;a href="http://www.fastcgi.com/" target="_blank"&gt;FastCGI&lt;/a&gt; process will keep running, waiting for more requests until its spun down as part of the web server.&amp;#160; So in this case using PHP, it eliminates the constant overhead of loading PHP into memory each time a request needs to be processed or course increasing the speed of the request. &lt;/p&gt;  &lt;p&gt;Also there are the &amp;#8220;NTS&amp;#8221; &lt;a href="http://www.php.net/downloads.php" target="_blank"&gt;non thread safe windows binaries of PHP&lt;/a&gt; that are available off the &lt;a href="http://php.net" target="_blank"&gt;php.net&lt;/a&gt; site - These binaries allow you to execute your code without needing to wait for thread synchronisation, meaning a HUGE performance increase. Couple this with FastCGI then you are you going to experiencing PHP running at a speed never before possible.&lt;/p&gt;  &lt;p&gt;To test this I ran a little test, for metrics sake this is Windows Server 2008 Enterprise running in Virtual PC 2007 - allocated 512MB of RAM. The host machine is a HP Compaq Laptop &lt;/p&gt;  &lt;p&gt;nc8430 Core 2 Duo @ 2.16Ghz and 4GB RAM, with a 7200 rpm disk, running Vista of course. My methodology was to grab a simple PHP site, run PHP with the standard CGI Module run a performance test, then change handler mapping to run the FastCGI Module and run the same performance test. The site I tested was on &lt;a href="http://qdig.sourceforge.net/Main/HomePage" target="_blank"&gt;Qdig&lt;/a&gt; and performance tests were using the &lt;a href="http://www.iis.net/downloads/default.aspx?tabid=34&amp;amp;g=6&amp;amp;i=1466" target="_blank"&gt;Web Capacity Analysis Tool (WCAT)&lt;/a&gt;. The metric measured was Get Requests / second, because this is an indication of how long the requests are taking before they need to be queued by the web server.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.technet.com/blogfiles/jorke/WindowsLiveWriter/HUGEperformanceincreaseswithPHPonWindows_B596/image_2.png"&gt;&lt;img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="289" alt="image" src="http://blogs.technet.com/blogfiles/jorke/WindowsLiveWriter/HUGEperformanceincreaseswithPHPonWindows_B596/image_thumb.png" width="521" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;On the left - NTS PHP with CGIModule - maximum approx 30 rps&lt;/p&gt;  &lt;p&gt;On the right - NTS PHP with FastCGIModule - maximum approx 870 rps&lt;/p&gt;  &lt;p&gt;Of course your mileage will vary, but &lt;strong&gt;you will&lt;/strong&gt; have a comparable or &lt;strong&gt;better&lt;/strong&gt; experience than on other platforms. &lt;/p&gt;  &lt;p&gt;Questions?&lt;/p&gt;  &lt;p&gt;-jorke&lt;/p&gt;  &lt;p&gt;   &lt;div class="wlWriterSmartContent" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:88c441f9-6c90-4130-afd2-6500e087273d" style="padding-right: 0px; display: inline; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px"&gt;Technorati Tags: &lt;a href="http://technorati.com/tags/PHP%20Performance" rel="tag"&gt;PHP Performance&lt;/a&gt;,&lt;a href="http://technorati.com/tags/PHP" rel="tag"&gt;PHP&lt;/a&gt;,&lt;a href="http://technorati.com/tags/IIS%207" rel="tag"&gt;IIS 7&lt;/a&gt;,&lt;a href="http://technorati.com/tags/IIS" rel="tag"&gt;IIS&lt;/a&gt;,&lt;a href="http://technorati.com/tags/Windows%20Server%202008" rel="tag"&gt;Windows Server 2008&lt;/a&gt;,&lt;a href="http://technorati.com/tags/FastCGI" rel="tag"&gt;FastCGI&lt;/a&gt;,&lt;a href="http://technorati.com/tags/CGI" rel="tag"&gt;CGI&lt;/a&gt;&lt;/div&gt;&lt;/p&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3036323" width="1" height="1"&gt;</description><category domain="http://blogs.technet.com/jorke/archive/tags/Microsoft/default.aspx">Microsoft</category><category domain="http://blogs.technet.com/jorke/archive/tags/Hosting/default.aspx">Hosting</category><category domain="http://blogs.technet.com/jorke/archive/tags/IIS/default.aspx">IIS</category><category domain="http://blogs.technet.com/jorke/archive/tags/Windows+Server+2008/default.aspx">Windows Server 2008</category><category domain="http://blogs.technet.com/jorke/archive/tags/IIS7/default.aspx">IIS7</category><category domain="http://blogs.technet.com/jorke/archive/tags/linux/default.aspx">linux</category><category domain="http://blogs.technet.com/jorke/archive/tags/CGI/default.aspx">CGI</category><category domain="http://blogs.technet.com/jorke/archive/tags/PHP/default.aspx">PHP</category><category domain="http://blogs.technet.com/jorke/archive/tags/FastCGI/default.aspx">FastCGI</category></item></channel></rss>