PHP on Windows 2008

28

description

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

Transcript of PHP on Windows 2008

Page 1: PHP on Windows 2008
Page 2: PHP on Windows 2008

Jorke OdolphiMicrosoft Australiaweb platform architect [email protected]@jorke

Page 3: PHP on Windows 2008

PHP Developers

longzheng

Page 4: PHP on Windows 2008

So Bacon has feathers now?

Contributing to Open Source

Open Specification Promise

Apache Software Foundation

Page 5: PHP on Windows 2008

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.

Send ResponseSend ResponseLogLog CompressCompress

NTLMNTLM BasicBasic

DeterminDetermine e

HandlerHandler

CGICGIStatic Static FileFile

ISAPIISAPI

AuthenticationAuthentication

AnonAnon

SendResponseSendResponse

AuthenticationAuthentication

Authorization

ResolveCache

ExecuteHandlerExecuteHandler

UpdateCache…

ASP.NET

PHP

Monolithic implementation Install all or all or nothingnothing…

Extend server functionality only through ISAPIISAPI…

Page 6: PHP on Windows 2008

IIS 6.0 ASP.NET Processing

Runtime limitations

Only sees ASP.NET requests

Feature duplication

Send ResponseSend ResponseLogLog CompressCompress

NTLMNTLM BasicBasic

DeterminDetermine e

HandlerHandler

CGICGIStatic Static FileFile

ISAPIISAPI

AuthenticationAuthenticationAnonAnon

AuthenticationFormForm

ssWindowWindow

ss

Map Handler

ASPXASPXTraceTrace

………

aspnet_isapi.dll

Page 7: PHP on Windows 2008

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

Page 8: PHP on Windows 2008

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++

Page 9: PHP on Windows 2008

IIS 7.0 ASP.NET Request Processing

Classic Mode• runs as ISAPI

Integrated Mode• .NET modules /

handlers plug directly into pipeline

• Process all requests• Full runtime fidelity

LogLog

CompressCompress

BasicBasic

Static Static FileFile

ISAPIISAPI

AnonAnon

SendResponseSendResponse

AuthenticationAuthentication

AuthorizationResolveCache

ExecuteHandlerExecuteHandler

UpdateCache…

…AuthenticationFormForm

ssWindowWindow

ss

Map Handle

r

ASPXASPXTraceTrace

………

aspnet_isapi.dll

Page 10: PHP on Windows 2008

New Configuration

NET global settings

.NET Framework Global web.configmachine.config

IIS 7applicationHost.config

Site Root web.config

<system.web>.NET settings

..

<system.webServer>IIS 7 Delegated settings

ASP.NET global

settings

Global settings and location

tags

Page 11: PHP on Windows 2008

PHP Setup

Page 12: PHP on Windows 2008

Per-site PHP configurationConfiguring FastCGI process pool

<fastCgi> <application fullPath="C:\PHP\php-cgi.exe" arguments="-d my.website=website1"> <environmentVariables> <environmentVariable name="PHPRC" value="C:\WebSites\website1" /> </environmentVariables> </application></fastCgi>

Combination of fullPath and arguments uniquely identify FastCGI process pool definition

PHPRC environment variable contains path to the php.ini file

Page 13: PHP on Windows 2008

Per-site PHP configurationConfiguring Handler Mapping

<system.webServer> <handlers accessPolicy="Read, Script"> <add name="PHP via FastCGI" path="*.php" verb="*" modules="FastCgiModule" scriptProcessor="C:\PHP\php-cgi.exe|-d my.website=website2" resourceType="Unspecified" requireAccess="Script" /> </handlers></system.webServer>

Reference FastCGI process pool by concatenating [fullPath]|[arguments]

Page 14: PHP on Windows 2008

PHP SetupFeature DelegationRemote AdministrationWeb Server Core Integration

Page 15: PHP on Windows 2008

Thread safe

Non Thread Safe

Page 16: PHP on Windows 2008

PHP with FastCGI

Zend Collaboration Built in Support for Fast CGI

Re-use of processes

BIG performance boost Thread Safe vs Non Thread Safe

Thread Safe

Non-Thread Safe

Page 17: PHP on Windows 2008

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

Page 18: PHP on Windows 2008

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>

Page 19: PHP on Windows 2008

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>

Page 20: PHP on Windows 2008

Manage CPU utilization

Windows Server Resource Manager (WSRM) Available in all SKU’s of WS2008 Ensures that process gets *at least* the

configured CPU percentage Kicks in only if overall CPU load is more

than 70% IIS team tested WSRM with 4000 web

sites

Page 21: PHP on Windows 2008

Performance Scaling OutWSRM

Page 22: PHP on Windows 2008

Performance Best Practices

Enable Output Caching for semi-dynamic pages Low bandwidth Branch Offices?

Enable Dynamic Compression (~ 5% CPU overhead)

Need to run many web apps on a single box? Run IIS worker processes in Wow64 mode

Room for the OS, scalability for your web apps It’s an per-AppPool setting now: Enable32BitAppOnWow64

Thinking about buying new Web Server hardware? W2K8 scales extremely well on new multi-proc boxes (4

and 8 core)

ASP.NET op caching vs. IIS op caching vs. KM output caching

Page 23: PHP on Windows 2008

Performance Best Practices

1000s of requests per second? Remove modules you don’t need

You don’t know why some pages are so slow? Turn on Failed Request Tracing and the “time-taken”

feature to investigate

You * script-mapped all requests to ASP.NET in IIS6? Integrated Pipeline is much faster than an IIS6 *

scriptmap solution Try together with IIS7 URL Authorization.

Page 24: PHP on Windows 2008

Performance Best Practices

PHP applications? PHP on top of FastCGI is much faster than traditional

CGI

The majority of your requests go to your Default Document? Put it on top of the list

Otherwise IIS7 has to check every time Static default documents will be cached in kernel-mode

Looking for tools to measures web server performance? Try WCAT 6.3 from www.iis.net/downloads

Page 25: PHP on Windows 2008

Performance Boosting Better compression for static and dynamic

Output caching a module Per URL / query string / request headers Huge improvements to allow for high density or

high availability

Page 26: PHP on Windows 2008

IIS Extensions

Mod_rewrite support for URL rewriting

Page 27: PHP on Windows 2008

Jorke Odolphi

[email protected]

Page 28: PHP on Windows 2008

Service Host Service Host (SVCHost.EXE)(SVCHost.EXE)

Windows Windows Process Process ActivatioActivatio

n n Service Service (WAS)(WAS)

World World Wide Web Wide Web

Service Service (W3SVC) (W3SVC)

applicationhost.conapplicationhost.configfig

SID Injection

AppPool: newPoolAppPool: newPoolusername: username: newPoolUsernewPoolUserpassword: password: <password><password>

LogonUser

LogonUser

Token

TokenToken

NewPool\NewPool\Wwwroot\Wwwroot\default.htdefault.ht

mm

ACL

Access

Check

Access

CheckOOKK

Otherpool\Otherpool\Wwwroot\Wwwroot\

default.htmdefault.htmACL

Access

Check

Access

CheckDenieDenie

dd