PHP + FastCGI
Performance Optimizations
             Alessandro Pilotti
            Twitter: @alexpilotti
            MVP ASP.NET / IIS




     MCSD, MCAD, MCSE, MCDBA, MCT
        Red Hat Certified Engineer
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
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?
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"
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%;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
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/
Demo
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
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!
FastCGI Setup
IIS FastCGI - Versions
Feature                 5.1/6.0   7.0   7.5
Monitoring file         Yes       Yes   Yes
changes
Real-Time max Inst.     Yes       Yes   Yes
tuning
STDERR support          Yes       Yes   Yes
SIGTERM support         Yes       Yes   Yes

Env. variable           Yes       Yes   Yes
_FCGI_X_PIPE_
Proc. Pool per          Yes       Yes   Yes
application
UTF-8 variable          Yes       Yes   No
encoding
IIS CPU Limit support   No        Yes   Yes
FastCGI - PHP
 Install PHP 5.2 or 5.3
    During setup choose FastCGI

 As an alternative, deploy via WebPI

 WP3P.exe
    Loads iisfcgi.dll
    Executes php-cgi.exe
 Config: PHP.INI
    E.g.: fastcgi.impersonate = 1
FastCGI - Settings
Handler Mappings
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
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)PHPv5.3php-
cgi.exe"
         resourceType="Either" />
     </handlers>
 </system.webServer>
</configuration>
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
PHP Manager
Set PHP Limits
PHP Error Reporting
Manage PHP.INI Settings
phpinfo() Output
PHP and FastCGI Performance Optimizations
PHP and FastCGI Performance Optimizations

More Related Content

PDF
Php Performance On Windows
PPTX
NodeJS
PDF
Workshop 4: NodeJS. Express Framework & MongoDB.
PPT
Dear Zoo Presentation for KS2 French & Spanish
PDF
버전관리를 들어본적 없는 사람들을 위한 DVCS - Git
PDF
Redis & ZeroMQ: How to scale your application
PPTX
10 Do's and 5 Don'ts for Small Biz Local SEO Success
Php Performance On Windows
NodeJS
Workshop 4: NodeJS. Express Framework & MongoDB.
Dear Zoo Presentation for KS2 French & Spanish
버전관리를 들어본적 없는 사람들을 위한 DVCS - Git
Redis & ZeroMQ: How to scale your application
10 Do's and 5 Don'ts for Small Biz Local SEO Success

What's hot (20)

PDF
코딩 테스트 및 알고리즘 문제해결 공부 방법 (고려대학교 KUCC, 2022년 4월)
PPT
레가시 프로젝트의 빌드 자동화
PPT
SLF4J (Simple Logging Facade for Java)
PPTX
React Native and React JS Advantages, Disadvantages and Features.pptx
PDF
SDLC - ICT Grade 11 Chapter 2 Tute Tamil Medium Sri Lanka
PDF
Glorioso san José
PDF
DITAR YONG STARS 1.pdf
PDF
Les nouveautés de Java 21 - Devoxx MA 2023.pdf
PDF
Accent on-achievement-libro-2-percusion
PDF
RedisConf18 - Redis Memory Optimization
PDF
Manual cool edit pro en españo l
PPT
Page object with selenide
DOCX
ODI 11g - Multiple Flat Files to Oracle DB Table by taking File Name dynamica...
PPTX
Build RESTful API Using Express JS
PDF
Mohamed thalha senior mes consultant Resume
PDF
우아한 객체지향
PPTX
QGIS-공간패턴을읽으면세상이보인다.
PDF
이벤트 기반 분산 시스템을 향한 여정
PDF
Quick flask an intro to flask
코딩 테스트 및 알고리즘 문제해결 공부 방법 (고려대학교 KUCC, 2022년 4월)
레가시 프로젝트의 빌드 자동화
SLF4J (Simple Logging Facade for Java)
React Native and React JS Advantages, Disadvantages and Features.pptx
SDLC - ICT Grade 11 Chapter 2 Tute Tamil Medium Sri Lanka
Glorioso san José
DITAR YONG STARS 1.pdf
Les nouveautés de Java 21 - Devoxx MA 2023.pdf
Accent on-achievement-libro-2-percusion
RedisConf18 - Redis Memory Optimization
Manual cool edit pro en españo l
Page object with selenide
ODI 11g - Multiple Flat Files to Oracle DB Table by taking File Name dynamica...
Build RESTful API Using Express JS
Mohamed thalha senior mes consultant Resume
우아한 객체지향
QGIS-공간패턴을읽으면세상이보인다.
이벤트 기반 분산 시스템을 향한 여정
Quick flask an intro to flask
Ad

Similar to PHP and FastCGI Performance Optimizations (20)

PPT
PHP on Windows 2008
PPT
PHP on Windows - What's New
PPT
Running PHP on Windows Technical Overview
PPT
Wordpress On Windows
PPT
Microsoft, PHP and IIS7
PPT
Php Presentation
PPT
Introduction to YII framework
PPTX
Wordpress on Windows
PPT
Php Asp Net Interoperability Rc Jao
PDF
Windows Loves Drupal
PDF
Automating Your Enterprise Application Deployments with PowerShell
PPTX
Partying with PHP on Microsoft Internet Information Services 7
TXT
Install
PDF
Secure PHP environment
PDF
Continuous integration / continuous delivery
PPTX
Windows Loves drupal
PPTX
Automating Your Enterprise Application Deployments With PowerShell by Geoff V...
PDF
Nginx pres
PPTX
Continuous integration / continuous delivery of web applications, Eugen Kuzmi...
PPT
IIS 6.0 and asp.net
PHP on Windows 2008
PHP on Windows - What's New
Running PHP on Windows Technical Overview
Wordpress On Windows
Microsoft, PHP and IIS7
Php Presentation
Introduction to YII framework
Wordpress on Windows
Php Asp Net Interoperability Rc Jao
Windows Loves Drupal
Automating Your Enterprise Application Deployments with PowerShell
Partying with PHP on Microsoft Internet Information Services 7
Install
Secure PHP environment
Continuous integration / continuous delivery
Windows Loves drupal
Automating Your Enterprise Application Deployments With PowerShell by Geoff V...
Nginx pres
Continuous integration / continuous delivery of web applications, Eugen Kuzmi...
IIS 6.0 and asp.net
Ad

More from Alessandro Pilotti (14)

PPTX
OpenStack and Windows - What's new in Ocata
PPTX
Strategies for migrating workloads from VMware to OpenStack
PPTX
Puppet + Windows Nano Server
PPTX
OpenStack + Nano Server + Hyper-V + S2D
PPTX
Building a Microsoft cloud with open technologies
PPTX
OpenStack Summit 2013 Hong Kong - OpenStack and Windows
PPTX
Interoperable OpenStack guest provisioning with Cloudbase-Init
PPTX
OpenStack and Windows
PPTX
An HTML5 client to connect to the Hyper-V console
PPTX
Hyper-V OpenStack Nova Compute
PPTX
Drupal, Memcache and Solr on Windows
PPTX
Managing Drupal on Windows with Drush
PPTX
Building drupal web farms with IIS - part 1
PPTX
Building modern web sites with ASP .Net Web API, WebSockets and RSignal
OpenStack and Windows - What's new in Ocata
Strategies for migrating workloads from VMware to OpenStack
Puppet + Windows Nano Server
OpenStack + Nano Server + Hyper-V + S2D
Building a Microsoft cloud with open technologies
OpenStack Summit 2013 Hong Kong - OpenStack and Windows
Interoperable OpenStack guest provisioning with Cloudbase-Init
OpenStack and Windows
An HTML5 client to connect to the Hyper-V console
Hyper-V OpenStack Nova Compute
Drupal, Memcache and Solr on Windows
Managing Drupal on Windows with Drush
Building drupal web farms with IIS - part 1
Building modern web sites with ASP .Net Web API, WebSockets and RSignal

Recently uploaded (20)

PDF
【AI論文解説】高速・高品質な生成を実現するFlow Map Models(Part 1~3)
PDF
Applying Agentic AI in Enterprise Automation
PDF
Ebook - The Future of AI A Comprehensive Guide.pdf
PDF
Introduction to c language from lecture slides
PPT
Overviiew on Intellectual property right
PDF
State of AI in Business 2025 - MIT NANDA
PPTX
Report in SIP_Distance_Learning_Technology_Impact.pptx
PDF
1_Keynote_Breaking Barriers_한계를 넘어서_Charith Mendis.pdf
PDF
Examining Bias in AI Generated News Content.pdf
PDF
ELLIE29.pdfWETWETAWTAWETAETAETERTRTERTER
PPTX
CRM(Customer Relationship Managmnet) Presentation
PPTX
Slides World Game (s) Great Redesign Eco Economic Epochs.pptx
PPTX
maintenance powerrpoint for adaprive and preventive
PDF
TicketRoot: Event Tech Solutions Deck 2025
PDF
GDG Cloud Southlake #45: Patrick Debois: The Impact of GenAI on Development a...
PDF
CCUS-as-the-Missing-Link-to-Net-Zero_AksCurious.pdf
PDF
Rooftops detection with YOLOv8 from aerial imagery and a brief review on roof...
PDF
Uncertainty-aware contextual multi-armed bandits for recommendations in e-com...
PPTX
From Curiosity to ROI — Cost-Benefit Analysis of Agentic Automation [3/6]
PDF
The Basics of Artificial Intelligence - Understanding the Key Concepts and Te...
【AI論文解説】高速・高品質な生成を実現するFlow Map Models(Part 1~3)
Applying Agentic AI in Enterprise Automation
Ebook - The Future of AI A Comprehensive Guide.pdf
Introduction to c language from lecture slides
Overviiew on Intellectual property right
State of AI in Business 2025 - MIT NANDA
Report in SIP_Distance_Learning_Technology_Impact.pptx
1_Keynote_Breaking Barriers_한계를 넘어서_Charith Mendis.pdf
Examining Bias in AI Generated News Content.pdf
ELLIE29.pdfWETWETAWTAWETAETAETERTRTERTER
CRM(Customer Relationship Managmnet) Presentation
Slides World Game (s) Great Redesign Eco Economic Epochs.pptx
maintenance powerrpoint for adaprive and preventive
TicketRoot: Event Tech Solutions Deck 2025
GDG Cloud Southlake #45: Patrick Debois: The Impact of GenAI on Development a...
CCUS-as-the-Missing-Link-to-Net-Zero_AksCurious.pdf
Rooftops detection with YOLOv8 from aerial imagery and a brief review on roof...
Uncertainty-aware contextual multi-armed bandits for recommendations in e-com...
From Curiosity to ROI — Cost-Benefit Analysis of Agentic Automation [3/6]
The Basics of Artificial Intelligence - Understanding the Key Concepts and Te...

PHP and FastCGI Performance Optimizations

  • 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/
  • 12. Demo
  • 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!
  • 16. IIS FastCGI - Versions Feature 5.1/6.0 7.0 7.5 Monitoring file Yes Yes Yes changes Real-Time max Inst. Yes Yes Yes tuning STDERR support Yes Yes Yes SIGTERM support Yes Yes Yes Env. variable Yes Yes Yes _FCGI_X_PIPE_ Proc. Pool per Yes Yes Yes application UTF-8 variable Yes Yes No encoding IIS CPU Limit support No Yes Yes
  • 17. FastCGI - PHP  Install PHP 5.2 or 5.3  During setup choose FastCGI  As an alternative, deploy via WebPI  WP3P.exe  Loads iisfcgi.dll  Executes php-cgi.exe  Config: PHP.INI  E.g.: fastcgi.impersonate = 1
  • 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
  • 21. 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)PHPv5.3php- cgi.exe" resourceType="Either" /> </handlers> </system.webServer> </configuration>
  • 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