php and fastcgi performance optimizations

Post on 13-May-2015

10.479 Views

Category:

Technology

2 Downloads

Preview:

Click to see full reader

DESCRIPTION

PHP is a first class citizen on IIS. A lot has been done in order to make sure that PHP can work well and fast on Windows. We will start by installing PHP with PHP Manager and discussing all the options including what thread safe vs non thread safe and VC6 vs VC9 means. Next we'll take a look at how to optimize the FastCGI IIS extension that Microsoft and Zend developed to provide a secure and performant environment for PHP applications. The last part of this webcast will show how to build PHP with Profile Guided Optimizations (PGO), a technique that can provide a significant performance boost in a wide range of applications.

TRANSCRIPT

PHP + FastCGI Performance Optimizations

Alessandro PilottiTwitter: @alexpilottiMVP ASP.NET / IIS

MCSD, MCAD, MCSE, MCDBA, MCTRed Hat Certified Engineer

PHP on IISFastCGI

Best available option

ISAPIThe way to go before FastCGILow reliability due to reentrance problemsDLL loaded at W3SVC instance level

Security issues

CGI (not FastCGI)Awful performance

How to get PHP on Windows

Binaries http://windows.php.NET/download/

Visual Studio C++ CRT DLL: VC6 or VC9? Apache: VC6 IIS: VC9

Thread safe or not thread safe? Thread safe for ISAPI Non Thread Safe for CGI/FastCGI

Massive performance improvement!

x86 vs x64 Do you need > 4GB of process space?

WebPIMicrosoft Web Platform Installer (WebPI) is a free tool that

simplifies deployment of web solutions IIS features and extensions

WinCache, PHP Drivers for SQL Server, PHP Manager Frameworks

.NET, PHP, etc Web applications

Drupal, Joomla, Wordpress, DotNetNuke, Orchard, etc Database

MS SQL Server Express, MySQL, etc WebMatrix

Both PHP 5.2 and 5.3 can be easily deployed via WebPI

Local cache: "%localappdata%\Microsoft\web platform installer\"

Deploy PHP via WebPI

Deploy PHP via WebPI

Deploy PHP via WebPI

Deploy PHP via WebPI

Compiling PHP If you want:

A PHP release available in sources A development build for testing purposes

What do you need: Sources, e.g.: http://php.NET/downloads.php Subversion client (e.g. TortoiseSVN) Instructions: https://wiki.php.net/internals/windows/stepbystepbuild PHP build extras

http://windows.php.net/downloads/php-sdk/ Deps and binaries: bison.exe, flex.exe, etc. and additional include and

libs Visual Studio 2008 or 2010

The Express edition (free) is enough

Compiling PHP Unpack the downloaded sources, e.g in c:\php-src

Use e.g 7-zip to inflate tar.gz or tar.bz

Or via SVN: svn checkout https://svn.php.NET/repository/php/php-

src/branches/PHP_5_4 php-src-5.4

Unpack the Win32 build extras in the same dir

Start a Visual Studio 2010 command prompt cd \php-src set PATH=%PATH%;win32build\bin set INCLUDE=%INCLUDE%;win32build\include set LIB=%LIB%;win32build\lib buildconf configure –disable-zts (and required extensions) nmake

Copy binaries (php-cgi.exe and php5.dll) to your PHP directory

Profile Guided Optimizations (PGO)

Feature of the MS C/C++ compiler (VS Professional or Premium)

Patch to PHP build environment available here: http://

www.ksingla.NET/wp-content/uploads/2010/05/pgo_build.patch.txt

Steps1. compile PHP with instrumentation enabled --enable-pgi

2. collect training data (.pgc files)

3. compile PHP with PGO –with-pgo

Expected performance improvement: 10-17%

More details http://

www.ksingla.NET/2010/05/php-pgo-build-for-maximum-performance-on-windows/

Demo

WebPI

PHP Deployment

CGI and FastCGICGI (Common Gateway Interface) is the oldest way

used to generate dynamic content on a web server A separate process is spawned for each request (!) Request input and response output are handled via

standard input / output Massive overhead due to process handling by the OS

FastCGI is a variation A separate process is spawned but persists among

multiple requests Request input and response output are handled via

sockets or named pipes Processes can be restarted independently Good performance Very popular in the Apache environment (mod_fastcgid),

for PHP, Perl, Ruby, etc

IIS FastCGI 1.5CGI is slow: every request generates a process instance!

FastCGI employs the same process for many requests

Supported on IIS 7.x and IIS 6.0 (the latter via fcgiext.dll ISAPI)

Written in collaboration with Zend (PHP) but is generic

In IIS 7.x: Enable CGI among the IIS role services

Note: Install Hotfix KB980363 on IIS 7.0 to get version 1.5!

FastCGI Setup

IIS FastCGI - VersionsFeature 5.1/6.0 7.0 7.5

Monitoring file changes

Yes Yes Yes

Real-Time max Inst. tuning

Yes Yes Yes

STDERR support Yes Yes Yes

SIGTERM support Yes Yes Yes

Env. variable _FCGI_X_PIPE_

Yes Yes Yes

Proc. Pool per application

Yes Yes Yes

UTF-8 variable encoding

Yes Yes No

IIS CPU Limit support

No Yes Yes

FastCGI - PHPInstall PHP 5.2 or 5.3

During setup choose FastCGI

As an alternative, deploy via WebPI

WP3P.exeLoads iisfcgi.dllExecutes php-cgi.exe

Config: PHP.INIE.g.: fastcgi.impersonate = 1

FastCGI - Settings

Handler Mappings

PHP.INI FastCGI Settingsfastcgi.impersonate

supports the ability to impersonate security tokens of the calling client

Default: 1

fastcgi.loggingTurns on SAPI logging when using FastCGIDefault: 1

Web.config - FastCGI<configuration>… <system.webServer> … <handlers> <clear /> <add name="PHP53_via_FastCGI" path="*.php" verb="GET,HEAD,POST" modules="FastCgiModule" scriptProcessor="C:\Program Files (x86)\PHP\v5.3\php-cgi.exe" resourceType="Either" /> </handlers> </system.webServer></configuration>

PHP ManagerA dedicated tool to support multiple PHP installations

Features:Easy management of the PHP version used by a web

appEasy management of the PHP parameters

No direct editing of PHP.INI neededEasy management of PHP ExtensionsBest practicesQuick inspections via phpinfo()Easy registration of new PHP installations

Deployable via WebPI or standalone setup

PHP Manager

Set PHP Limits

PHP Error Reporting

Manage PHP.INI Settings

phpinfo() Output

Deploy PHP via WebPI

Optimize PHP with PGO

top related