Running PHP on Windows Technical Overview - Download Center

Document Sample
Running PHP on Windows Technical Overview - Download Center Powered By Docstoc
					Running PHP on Windows
Server 2008 and IIS 7
Rob Cameron
Developer Evangelist, Communications Sector
Microsoft
Session Objectives And Agenda

 Objectives
   Learn how to host existing PHP applications on IIS
   Learn how to take advantage of IIS7 to extend existing PHP
   applications with ASP.NET
 Agenda
   Running PHP applications on IIS7
   Deploying and managing PHP applications on IIS7
   Extending PHP applications with IIS7
   Best practices
IIS6 Application Framework support

 Common Gateway Interface (CGI) for CGI and PHP
 applications
   Benefits
      Very simple to implement and use – single-threaded execution
   Disadvantages
      Poor performance due to high process creation cost
      Creates and passes request data to a new CGI process
      Waits for CGI process to produce response
      Shuts down CGI process
IIS6 Application Framework support

 Internet Server Application Programming Interface (ISAPI)
    Benefit of ISAPI
       Can be extremely fast when written correctly
    Disadvantage of ISAPI
       Must be thread-safe (many PHP extensions are not!)
       Requires development in C++
FastCGI in IIS7

 FastCGI: the best of both CGI and ISAPI
   Enhancement to CGI protocol
   Web server creates FastCGI process for very first request
   Web server re-uses existing FastCGI process for subsequent
   requests
   Ships as part of IIS7, installed with the CGI feature
 Benefits of FastCGI for Windows OS
   Much faster than CGI because there is no process creation
   cost
   Much more stable than ISAPI because of single threaded
   execution environment

   Non-thread safe PHP build is recommended for
                      FastCGI
FastCGI Handler Architecture

                                            FastCGI process pool for
                                                    PHP5
                         FastCGI protocol
    IIS Worker Process   over named pipes
                         or TCP




                                                 php-cgi.exe




                                            FastCGI process pool for
                                                    PHP4




              Request                              php.exe
               queue
Installing FastCGI and PHP
on IIS7
DEMO
Deploying PHP applications on IIS7
 Control IIS configuration for PHP applications via
 web.config
    Example: setting default document for PHP application
 Run PHP applications in the new IIS7 integrated
 pipeline with ASP.NET and other web applications
    Extend existing PHP applications with rich ASP.NET
    functionality
    Develop new .NET modules that run in the integrated pipeline
    to handle PHP requests the same way as the module handles
    requests for ASP.NET content.
    Example: URL Rewriter that makes “pretty” URLs for PHP and
    ASP.NET content.
Extending PHP in the Integrated
Pipeline
  IIS7’s Integrated Pipeline enables ASP.NET to serve as
  the standard .NET extensibility mechanism for IIS7.
  Provides the same familiar ASP.NET APIs and features
  for building web applications.
  ASP.NET provides a rich application framework for
  rapid application extensions to existing PHP
  applications.
Example: Adding Access Control to an existing PHP application….
Using PHP                            Using ASP.NET
Building a custom credential store   Rich membership service, built-in
and cookie-based authentication      credential store providers, the forms
from the ground up.                  authentication module, and
                                     a set of pre-made Login controls.
Extending Existing PHP
Applications with ASP.NET in
the IIS7 Integrated Pipeline
DEMO
Best Practices for Running PHP on
IIS7
 Want to ensure that a new process is created if no processes are
 available to handle a request?
    Run one instance per CPU with a minimum of 4 instances
    Set maxInstances to the lowest possible number under full load
    without consuming 100% CP
 Want to make sure that the existing process is recycled
 periodically?
    Set instanceMaxRequests (number of requests to process before
    recycling) as high as possible without destabilizing the app
    PHP process’ maximum request setting (PHP_fcgi_max_requests)
    has to be equal or higher than the instanceMaxRequests setting.
<fastCgi>
    <application fullPath="C:\PHP\php-cgi.exe"
        maxInstances="4"
        instanceMaxRequests="10000"
        idleTimeout="300"/>
</fastCgi>
Best Practices for Running PHP on
IIS7
 Want to set PHP specific environment variables in the
 web.config file?
    Use environmentVariables configuration setting to set PHP
    specific environment variables.


<fastCgi>
   <application fullPath="C:\PHP\php-cgi.exe"
       instanceMaxRequests=“10000">
       <environmentVariables>
              <environmentVariable
                     name=”PHP_FCGI_MAX_REQUESTS”
                     value=”10000”/>
      </environmentVariables>
   </application>
</fastCgi>
Best Practices for Running PHP on
IIS7
 Is your server under so much load that your clients are
 getting timeout responses?
    The FastCGI process will be terminated if it does not respond
    to FastCGI handler within specified time period.
    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.

<fastCgi>
   <application fullPath="C:\PHP\php-cgi.exe"
      activityTimeout=“30"
      requestTimeout=“90"/>
</fastCgi>
FastCGI Best Practices
 Want to use FastCGI process security context?
   Application pool identity is used for FastCGI process
   Use fcgi.impersonate PHP setting if client impersonation is
   necessary
 Need support for FastCGI and PHP on Windows
 Server?
   http://forums.iis.net
 Looking for support from the community?
   http://www.iis.net/php
 Want to ensure serviceability and patching of PHP for
 business critical apps?
   Consider Zend’s commercial offerings (Zend Core)
 Need FastCGI for IIS6 installations?
   FastCGI Extension for IIS6 is now available for download!
Summary

 FastCGI for IIS6 is now available for download!
 FastCGI radically improves the reliability and
 performance for existing PHP applications on both IIS6
 and IIS7
 The new integrated pipeline in IIS7 introduces the
 ability to extend existing PHP applications with
 ASP.NET, as well as develop managed modules that
 handle requests for any web application (ASP.NET,
 PHP, Ruby, etc.) in the request pipeline
IIS.NET: Home for IIS Community!
       In-depth technical articles and samples

   Connect with other IIS experts on blogs & forums

        Free advice and assistance in forums

          Download center with IIS solutions

				
DOCUMENT INFO
Shared By:
Categories:
Tags:
Stats:
views:0
posted:11/20/2012
language:Unknown
pages:16