Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

PHP on Windows 2008

2,628 views

Published on

Presentation on PHP on Windows 2008 presented at OSDC 2008 in Sydney

Published in: Technology
  • Be the first to comment

PHP on Windows 2008

  1. 2. Jorke Odolphi Microsoft Australia web platform architect evangelist [email_address] @jorke
  2. 3. PHP Developers longzheng
  3. 4. So Bacon has feathers now? Contributing to Open Source Open Specification Promise Apache Software Foundation
  4. 5. IIS Request Processing Server functionality is split into ~ 40 modules... Modules plug into a generic request pipeline… Modules extend server functionality through a public module API. Authorization ResolveCache UpdateCache … … … Monolithic implementation Install all or nothing … Extend server functionality only through ISAPI … Send Response Log Compress NTLM Basic Determine Handler CGI Static File ISAPI Authentication Anon SendResponse Authentication ExecuteHandler ASP.NET PHP
  5. 6. IIS 6.0 ASP.NET Processing Runtime limitations Only sees ASP.NET requests Feature duplication … … … … aspnet_isapi.dll Send Response Log Compress NTLM Basic Determine Handler CGI Static File ISAPI Authentication Anon Authentication Forms Windows Map Handler ASPX Trace …
  6. 7. IIS6 Application Framework support <ul><li>Common Gateway Interface (CGI) for CGI and PHP applications </li></ul><ul><ul><li>Benefits </li></ul></ul><ul><ul><ul><li>Very simple to implement and use – single-threaded execution </li></ul></ul></ul><ul><ul><li>Disadvantages </li></ul></ul><ul><ul><ul><li>Poor performance due to high process creation cost </li></ul></ul></ul><ul><ul><ul><li>Creates and passes request data to a new CGI process </li></ul></ul></ul><ul><ul><ul><li>Waits for CGI process to produce response </li></ul></ul></ul><ul><ul><ul><li>Shuts down CGI process </li></ul></ul></ul>
  7. 8. IIS6 Application Framework support <ul><li>Internet Server Application Programming Interface (ISAPI) </li></ul><ul><ul><li>Benefit of ISAPI </li></ul></ul><ul><ul><ul><li>Can be extremely fast when written correctly </li></ul></ul></ul><ul><ul><li>Disadvantage of ISAPI </li></ul></ul><ul><ul><ul><li>Must be thread-safe (many PHP extensions are not!) </li></ul></ul></ul><ul><ul><ul><li>Requires development in C++ </li></ul></ul></ul>
  8. 9. IIS 7.0 ASP.NET Request Processing <ul><li>Classic Mode </li></ul><ul><ul><li>runs as ISAPI </li></ul></ul><ul><li>Integrated Mode </li></ul><ul><ul><li>.NET modules / handlers plug directly into pipeline </li></ul></ul><ul><ul><li>Process all requests </li></ul></ul><ul><ul><li>Full runtime fidelity </li></ul></ul>Authorization ResolveCache UpdateCache … … … … aspnet_isapi.dll Log Compress Basic Static File ISAPI Anon SendResponse Authentication ExecuteHandler Authentication Forms Windows Map Handler ASPX Trace …
  9. 10. New Configuration NET global settings .NET Framework Global web.config machine.config IIS 7 applicationHost.config Site Root web.config <system.web> .NET settings .. <system.webServer> IIS 7 Delegated settings ASP.NET global settings Global settings and location tags
  10. 11. PHP Setup
  11. 12. Per-site PHP configuration Configuring FastCGI process pool < fastCgi > < application fullPath =&quot;C:PHPphp-cgi.exe&quot; arguments =&quot;-d my.website=website1&quot;> < environmentVariables > < environmentVariable name =&quot;PHPRC&quot; value =&quot;C:WebSiteswebsite1&quot; /> </ environmentVariables > </ application > </ fastCgi > Combination of fullPath and arguments uniquely identify FastCGI process pool definition PHPRC environment variable contains path to the php.ini file
  12. 13. Per-site PHP configuration Configuring Handler Mapping < system.webServer > < handlers accessPolicy =&quot;Read, Script&quot;> < add name =&quot;PHP via FastCGI&quot; path =&quot;*.php&quot; verb =&quot;*&quot; modules =&quot;FastCgiModule&quot; scriptProcessor =&quot;C:PHPphp-cgi.exe|-d my.website=website2&quot; resourceType =&quot;Unspecified&quot; requireAccess =&quot;Script&quot; /> </ handlers > </ system.webServer > Reference FastCGI process pool by concatenating [fullPath]|[arguments]
  13. 14. PHP Setup Feature Delegation Remote Administration Web Server Core Integration
  14. 15. Thread safe Non Thread Safe
  15. 16. PHP with FastCGI <ul><li>Zend Collaboration </li></ul><ul><li>Built in Support for Fast CGI </li></ul><ul><ul><li>Re-use of processes </li></ul></ul><ul><li>BIG performance boost </li></ul><ul><li>Thread Safe vs Non Thread Safe </li></ul>Thread Safe Non-Thread Safe
  16. 17. FastCGI Handler Architecture IIS Worker Process Request queue FastCGI process pool for PHP5 php-cgi.exe FastCGI process pool for PHP4 php.exe FastCGI protocol over named pipes or TCP
  17. 18. Best Practices for Running PHP on IIS7 <ul><li>Want to set PHP specific environment variables in the web.config file? </li></ul><ul><ul><li>Use environmentVariables configuration setting to set PHP specific environment variables. </li></ul></ul><ul><li><fastCgi> </li></ul><ul><ul><li><application fullPath=&quot;C:PHPphp-cgi.exe&quot; </li></ul></ul><ul><ul><li>instanceMaxRequests=“10000&quot;> </li></ul></ul><ul><ul><li><environmentVariables> </li></ul></ul><ul><ul><li>    <environmentVariable </li></ul></ul><ul><ul><li>name=”PHP_FCGI_MAX_REQUESTS” </li></ul></ul><ul><ul><li>value=”10000”/> </li></ul></ul><ul><ul><li>    </environmentVariables> </li></ul></ul><ul><ul><li></application> </li></ul></ul><ul><li></fastCgi> </li></ul>
  18. 19. Best Practices for Running PHP on IIS7 <ul><li>Is your server under so much load that your clients are getting timeout responses? </li></ul><ul><ul><li>The FastCGI process will be terminated if it does not respond to FastCGI handler within specified time period. </li></ul></ul><ul><ul><li>Set the requestTimeout (number of seconds to wait for process to handle the request) value to be higher than the activityTimeout (number of seconds to wait for any process activity) value. </li></ul></ul><ul><li><fastCgi> </li></ul><ul><ul><li><application fullPath=&quot;C:PHPphp-cgi.exe&quot; </li></ul></ul><ul><ul><li>activityTimeout=“30&quot; </li></ul></ul><ul><ul><li>requestTimeout=“90&quot;/> </li></ul></ul><ul><li></fastCgi> </li></ul>
  19. 20. Manage CPU utilization <ul><li>Windows Server Resource Manager (WSRM) </li></ul><ul><ul><li>Available in all SKU’s of WS2008 </li></ul></ul><ul><ul><li>Ensures that process gets *at least* the configured CPU percentage </li></ul></ul><ul><ul><li>Kicks in only if overall CPU load is more than 70% </li></ul></ul><ul><li>IIS team tested WSRM with 4000 web sites </li></ul>
  20. 21. Performance Scaling Out WSRM
  21. 22. Performance Best Practices <ul><li>Enable Output Caching for semi-dynamic pages </li></ul><ul><li>Low bandwidth Branch Offices? </li></ul><ul><ul><li>Enable Dynamic Compression ( ~ 5% CPU overhead) </li></ul></ul><ul><li>Need to run many web apps on a single box? </li></ul><ul><ul><li>Run IIS worker processes in Wow64 mode </li></ul></ul><ul><ul><ul><li>Room for the OS, scalability for your web apps </li></ul></ul></ul><ul><ul><ul><li>It’s an per-AppPool setting now: Enable32BitAppOnWow64 </li></ul></ul></ul><ul><li>Thinking about buying new Web Server hardware? </li></ul><ul><ul><li>W2K8 scales extremely well on new multi-proc boxes (4 and 8 core) </li></ul></ul><ul><li>ASP.NET op caching vs. IIS op caching vs. KM output caching </li></ul>
  22. 23. Performance Best Practices <ul><li>1000s of requests per second? </li></ul><ul><ul><li>Remove modules you don’t need </li></ul></ul><ul><li>You don’t know why some pages are so slow? </li></ul><ul><ul><li>Turn on Failed Request Tracing and the “time-taken” feature to investigate </li></ul></ul><ul><li>You * script-mapped all requests to ASP.NET in IIS6? </li></ul><ul><ul><li>Integrated Pipeline is much faster than an IIS6 * scriptmap solution </li></ul></ul><ul><ul><li>Try together with IIS7 URL Authorization. </li></ul></ul>
  23. 24. Performance Best Practices <ul><li>PHP applications? </li></ul><ul><ul><li>PHP on top of FastCGI is much faster than traditional CGI </li></ul></ul><ul><li>The majority of your requests go to your Default Document? </li></ul><ul><ul><li>Put it on top of the list </li></ul></ul><ul><ul><ul><li>Otherwise IIS7 has to check every time </li></ul></ul></ul><ul><ul><ul><li>Static default documents will be cached in kernel-mode </li></ul></ul></ul><ul><li>Looking for tools to measures web server performance? </li></ul><ul><ul><li>Try WCAT 6.3 from www.iis.net/downloads </li></ul></ul>
  24. 25. Performance Boosting <ul><li>Better compression for static and dynamic </li></ul><ul><ul><li>Output caching a module </li></ul></ul><ul><ul><li>Per URL / query string / request headers </li></ul></ul><ul><ul><li>Huge improvements to allow for high density or high availability </li></ul></ul>
  25. 26. IIS Extensions <ul><li>Mod_rewrite support for URL rewriting </li></ul>
  26. 27. Jorke Odolphi [email_address]
  27. 28. SID Injection AppPool: newPool username: newPoolUser password: <password> LogonUser AccessCheck AccessCheck Service Host (SVCHost.EXE) Windows Process Activation Service (WAS) World Wide Web Service (W3SVC) applicationhost.config Token Token NewPool Wwwroot default.htm ACL OK Otherpool Wwwroot default.htm ACL Denied

×