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.
1. PHP + FastCGI
Performance Optimizations
Alessandro Pilotti
Twitter: @alexpilotti
MVP ASP.NET / IIS
MCSD, MCAD, MCSE, MCDBA, MCT
Red Hat Certified Engineer
2. PHP on IIS
FastCGI
Best available option
ISAPI
The way to go before FastCGI
Low reliability due to reentrance problems
DLL loaded at W3SVC instance level
Security issues
CGI (not FastCGI)
Awful performance
3. 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?
4. WebPI
Microsoft 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%Microsoftweb platform installer"
9. 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
10. 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%;win32buildbin
set INCLUDE=%INCLUDE%;win32buildinclude
set LIB=%LIB%;win32buildlib
buildconf
configure –disable-zts (and required extensions)
nmake
Copy binaries (php-cgi.exe and php5.dll) to your PHP directory
11. 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
Steps
1. 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/
13. CGI and FastCGI
CGI (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
14. IIS FastCGI 1.5
CGI 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!
20. PHP.INI FastCGI Settings
fastcgi.impersonate
supports the ability to impersonate security tokens of the
calling client
Default: 1
fastcgi.logging
Turns on SAPI logging when using FastCGI
Default: 1
22. PHP Manager
A dedicated tool to support multiple PHP installations
Features:
Easy management of the PHP version used by a web app
Easy management of the PHP parameters
No direct editing of PHP.INI needed
Easy management of PHP Extensions
Best practices
Quick inspections via phpinfo()
Easy registration of new PHP installations
Deployable via WebPI or standalone setup