SlideShare a Scribd company logo
Mod PHP and Fast CGI

    {
{

    {Where did we come from?
{      Where are we going?
  Why did we need to get here?

        A look at FastCgi & Mod_PHP architecture


[
               Aimee Maree Forsstrom
The beginning

• HTML Tags – 1991
• HTML v2.0 - 1995
• HTTP v1.0 – 1996

• Computer says
  “213.236.210.9
  Show me your
  home page”
• Web server says
  “HTTP 200 OK
  Here you go
  <HTML> …
  </HTML>”
Dynamic Scripts
• CGI – 1993
• Receives PHP page
  request
• Loads PHP
  environment
• Executes request
• Kills environment
• Cleans it all up
• Repeats for every
  request, yes
  every single one!
Limitations
• The architecture with the worst
  performance. Why?
• Creates new process for every request
• Debugging CGI scripts traditionally
  been difficult. Why?
• Because, hard to study standard output
  and errors
• MOD_PHP and FastCGI came about at the
  same time to deal with the problems of
  CGI


          [                   ]
• .
Mod_PHP takes over
• Apache becomes forerunner
•

                                        ^
  Mod_PHP gains momentum
• Loads as Apache child process


                                        ^
• Preloads PHP environment
• Low latency


                                        ^
• Use persistent database sessions
• Shared memory
• Two requests or one after the other
  can share memory between


                                        ^
• Store persistent data in memory
  (xcache, APC, etc)
Mod|PHP the Downside

• Uses Apache Permission > runs as www
• Increases Apaches memory usage >
  Parent – Child design > need 100
  apache children, if each one uses
  100mb then 1GB of memory needed
• Slows down Apache as Apache does the
  work of PHP
• Apache needs to restart the child
• Leads to loss of connection
• Not suitable for scaling across
  multiple servers 
Mod_PHP
• Checks queue then parses request
• Is it static? Yes/No? Either way > Apache
How does Apache work

•   Procedural based parent/child design
•   Listener at the front
•   Listener places request in queue
•   Queue processed bottom first
•   Therefore, first come first served
•   Backend checks for new processes
•   Pick request from queue
•   Processes request returns results
•   Apache decides what to do with it?
•   PHP runs as a apache child
•   Therefore it can do nothing else until
    the script executes/times out and
    mark-up is delivered
Apache gets a work-out

• Backend =
  mod_php
• Architecture
  leads to
  blocking
• Apache says?
• Spawn more
  backends
• But?
• We run out of
  memory?
• Solution =
  limit them!
• But now the
  queue fills
  up? #fail
Mod_PHP fails
1b.Incoming
requests are
dropped
2b. Queue
fills up and
fails
One + One = Two?


Page load time =

                     {
PHP script load
         +       {
  static load
                [
Fast[Cgi takes over
• Parent/Child model
• Apache does not handle PHP children
  FastCGI does
• Web servers like Apache don’t like
  processing applications
• Web servers like dealing with static
  requests
• Separates application from the web
  server


                                ]
• Web server becomes proxy server and
  sends PHP requests to FCGI
Fast[CGI benefits
• Preloads PHP environment
• Webserver free to process static
  content
• FastCGI handles only PHP requests
• Server does not die if PHP script dies
• Natively load balanced
• Round robin load balancing effect
• Restart PHP without restarting server
• Make configuration changes on the fly


                   _            |
Fast[CGI                ]
• Apache decides if dynamic script
• If yes, hands across to fastCGI
• PHP load does not effect mark-up load
Fast CGI dispatcher
• Similar
  workflow to
  HTTP, but?
• FastCgi is its
  protocol
• Not HTTP
• Listener takes
  request
• Places in queue
• Backends pick
  up
• Processes
  results
Fast[CGI Load Balanced

• Web Server & FCGI Dispatcher separate
• Dispatch among servers randomly
• Dispatch among servers based on list
how are they different?

• FastCGI is interprocess communication
• And mod_PHP is an in-process module

             Example
Persistent connections
Mod_php every persistent connection
would own connection to the database.
This can be expensive as some
connections would be serving static
content such as image files.
the difference

              It’s the
              bottle
              neck


The load is
   balanced
    in FCGI
The future is bright
• Fast CGI, but it’s old? So get into it
  finally!
• Load Balancing
• Increased Security as each backend runs
  as different user
• Multiple PHP environment support 5.2/5.3
• Restart PHP without one dropped
  connection
• Configuration changes without dropping
  connections
• Not language specific
• PHP runs FastCGI natively inside
  application
• PHP compile time option
Thank you
       @aimee_maree
    www.aimeemaree.com




|

More Related Content

What's hot (20)

PDF
Ansible Introduction
Robert Reiz
 
PPTX
Understanding GIT and Version Control
Sourabh Sahu
 
PDF
Kubernetes - A Comprehensive Overview
Bob Killen
 
PPTX
Container Orchestration using Kubernetes
Hesham Amin
 
PDF
AWS DevOps - Terraform, Docker, HashiCorp Vault
Grzegorz Adamowicz
 
ODP
Introduction to Nginx
Knoldus Inc.
 
PPTX
서버 아키텍처 이해를 위한 프로세스와 쓰레드
KwangSeob Jeong
 
PPTX
Web services SOAP
princeirfancivil
 
PPTX
Docker Networking Overview
Sreenivas Makam
 
PPTX
What is Ajax technology?
JavaTpoint.Com
 
PDF
Design Pattern (Strategy & Template)
Alia Hamwi
 
PDF
Kubernetes Basics
Eueung Mulyana
 
PPTX
BitBucket presentation
Jonathan Lawerh
 
PPTX
Docker Tutorial For Beginners | What Is Docker And How It Works? | Docker Tut...
Simplilearn
 
PDF
Containers technologies
Joris Bonnefoy
 
PPTX
Postman Collection Format v2.0 (pre-draft)
Postman
 
PPTX
Apache Zeppelin + LIvy: Bringing Multi Tenancy to Interactive Data Analysis
DataWorks Summit/Hadoop Summit
 
PPTX
ASP.NET Core MVC + Web API with Overview
Shahed Chowdhuri
 
PDF
Clouds and Tools: Cheat Sheets & Infographics
Thomas Poetter
 
PPTX
Web application
maliksiddique1
 
Ansible Introduction
Robert Reiz
 
Understanding GIT and Version Control
Sourabh Sahu
 
Kubernetes - A Comprehensive Overview
Bob Killen
 
Container Orchestration using Kubernetes
Hesham Amin
 
AWS DevOps - Terraform, Docker, HashiCorp Vault
Grzegorz Adamowicz
 
Introduction to Nginx
Knoldus Inc.
 
서버 아키텍처 이해를 위한 프로세스와 쓰레드
KwangSeob Jeong
 
Web services SOAP
princeirfancivil
 
Docker Networking Overview
Sreenivas Makam
 
What is Ajax technology?
JavaTpoint.Com
 
Design Pattern (Strategy & Template)
Alia Hamwi
 
Kubernetes Basics
Eueung Mulyana
 
BitBucket presentation
Jonathan Lawerh
 
Docker Tutorial For Beginners | What Is Docker And How It Works? | Docker Tut...
Simplilearn
 
Containers technologies
Joris Bonnefoy
 
Postman Collection Format v2.0 (pre-draft)
Postman
 
Apache Zeppelin + LIvy: Bringing Multi Tenancy to Interactive Data Analysis
DataWorks Summit/Hadoop Summit
 
ASP.NET Core MVC + Web API with Overview
Shahed Chowdhuri
 
Clouds and Tools: Cheat Sheets & Infographics
Thomas Poetter
 
Web application
maliksiddique1
 

Viewers also liked (13)

PPT
Common Gateway Interface
Piero Fraternali
 
PPTX
PHP and FastCGI Performance Optimizations
Alessandro Pilotti
 
KEY
PyCon US 2012 - State of WSGI 2
Graham Dumpleton
 
KEY
Large platform architecture in (mostly) perl - an illustrated tour
Tomas Doran
 
PPT
A Brief Introduce to WSGI
Mingli Yuan
 
PDF
PHP Files: An Introduction
Jacques Woodcock
 
KEY
Intro to PSGI and Plack
Tatsuhiko Miyagawa
 
PDF
mod_php vs FastCGI vs FPM vs CLI
Jacques Woodcock
 
PPT
Common gateway interface
Anandita
 
PDF
FCGI, C++로 Restful 서버 개발
현승 배
 
PPT
CGI Presentation
Sopan Shewale
 
PDF
WSGI, Django, Gunicorn
Benoit Chesneau
 
PPTX
php and sapi and zendengine2 and...
do_aki
 
Common Gateway Interface
Piero Fraternali
 
PHP and FastCGI Performance Optimizations
Alessandro Pilotti
 
PyCon US 2012 - State of WSGI 2
Graham Dumpleton
 
Large platform architecture in (mostly) perl - an illustrated tour
Tomas Doran
 
A Brief Introduce to WSGI
Mingli Yuan
 
PHP Files: An Introduction
Jacques Woodcock
 
Intro to PSGI and Plack
Tatsuhiko Miyagawa
 
mod_php vs FastCGI vs FPM vs CLI
Jacques Woodcock
 
Common gateway interface
Anandita
 
FCGI, C++로 Restful 서버 개발
현승 배
 
CGI Presentation
Sopan Shewale
 
WSGI, Django, Gunicorn
Benoit Chesneau
 
php and sapi and zendengine2 and...
do_aki
 
Ad

Similar to A look at FastCgi & Mod_PHP architecture (20)

PDF
PHP, Handle with care
Phill Brown
 
PDF
How PHP works
Atlogys Technical Consulting
 
PDF
Php through the eyes of a hoster confoo
Combell NV
 
PPT
Download It
webhostingguy
 
PDF
Secure PHP environment
SpeedPartner GmbH
 
PPTX
Apache web server
Rishabh Bahukhandi
 
PPSX
webservers
Ewere Diagboya
 
ODP
Choosing a Web Architecture for Perl
Perrin Harkins
 
PDF
Apache2 BootCamp : Serving Dynamic Content with CGI
Wildan Maulana
 
PPT
Tech talk: PHP
Jen Wei Lee
 
PDF
Web servers presentacion
Kiwi Science
 
KEY
SydPHP March 2012 Meetup
Graham Weldon
 
PDF
Integrating PHP With System-i using Web Services
Ivo Jansch
 
PPTX
Introduction to PHP.pptx
MarianJRuben
 
PDF
Php through the eyes of a hoster phpbnl11
Combell NV
 
PDF
t1837
tutorialsruby
 
PDF
t1837
tutorialsruby
 
PPTX
PHP Hypertext Preprocessor
adeel990
 
KEY
Php through the eyes of a hoster: PHPNW10
Combell NV
 
PDF
Nginx pres
James Fuller
 
PHP, Handle with care
Phill Brown
 
Php through the eyes of a hoster confoo
Combell NV
 
Download It
webhostingguy
 
Secure PHP environment
SpeedPartner GmbH
 
Apache web server
Rishabh Bahukhandi
 
webservers
Ewere Diagboya
 
Choosing a Web Architecture for Perl
Perrin Harkins
 
Apache2 BootCamp : Serving Dynamic Content with CGI
Wildan Maulana
 
Tech talk: PHP
Jen Wei Lee
 
Web servers presentacion
Kiwi Science
 
SydPHP March 2012 Meetup
Graham Weldon
 
Integrating PHP With System-i using Web Services
Ivo Jansch
 
Introduction to PHP.pptx
MarianJRuben
 
Php through the eyes of a hoster phpbnl11
Combell NV
 
PHP Hypertext Preprocessor
adeel990
 
Php through the eyes of a hoster: PHPNW10
Combell NV
 
Nginx pres
James Fuller
 
Ad

More from Aimee Maree (20)

PPTX
AI - PAST, PRESENT, FUTURE.pptx
Aimee Maree
 
PPTX
Pioneering Technology - My Story
Aimee Maree
 
PPTX
DOM and Accessibility API Communication
Aimee Maree
 
PPT
Machine Learning ate my homework
Aimee Maree
 
PDF
Accessiblity 101 and JavaScript Frameworks
Aimee Maree
 
ODP
Accessibility, SEO and Joomla
Aimee Maree
 
PPTX
The Good, The Bad, The Voiceover - ios Accessibility
Aimee Maree
 
PDF
Javascript Framework Acessibiliity Review
Aimee Maree
 
PDF
DeCoupling Drupal
Aimee Maree
 
PDF
Diversity through iOS Development - App Camp 4 Girls
Aimee Maree
 
ODP
Waving an Open Source Flag in Australian Government
Aimee Maree
 
ODP
Cyber Terrorism or Terrible Code
Aimee Maree
 
ODP
Govhack - Collections of World War One Connecting the Dots
Aimee Maree
 
ODP
Accessibility with Joomla [on a budget]
Aimee Maree
 
ODP
FirefoxOS and its use of Linux (a deep dive into Gonk architecture)
Aimee Maree
 
ODP
Introduction to Python - Training for Kids
Aimee Maree
 
PPT
UK Communications Bill Proposed Changes 2012
Aimee Maree
 
ODP
Welcome to the World of Trolls
Aimee Maree
 
PPT
Drupal7 themeing changes and inheritence
Aimee Maree
 
PPTX
Drupal’s growth
Aimee Maree
 
AI - PAST, PRESENT, FUTURE.pptx
Aimee Maree
 
Pioneering Technology - My Story
Aimee Maree
 
DOM and Accessibility API Communication
Aimee Maree
 
Machine Learning ate my homework
Aimee Maree
 
Accessiblity 101 and JavaScript Frameworks
Aimee Maree
 
Accessibility, SEO and Joomla
Aimee Maree
 
The Good, The Bad, The Voiceover - ios Accessibility
Aimee Maree
 
Javascript Framework Acessibiliity Review
Aimee Maree
 
DeCoupling Drupal
Aimee Maree
 
Diversity through iOS Development - App Camp 4 Girls
Aimee Maree
 
Waving an Open Source Flag in Australian Government
Aimee Maree
 
Cyber Terrorism or Terrible Code
Aimee Maree
 
Govhack - Collections of World War One Connecting the Dots
Aimee Maree
 
Accessibility with Joomla [on a budget]
Aimee Maree
 
FirefoxOS and its use of Linux (a deep dive into Gonk architecture)
Aimee Maree
 
Introduction to Python - Training for Kids
Aimee Maree
 
UK Communications Bill Proposed Changes 2012
Aimee Maree
 
Welcome to the World of Trolls
Aimee Maree
 
Drupal7 themeing changes and inheritence
Aimee Maree
 
Drupal’s growth
Aimee Maree
 

Recently uploaded (20)

PPTX
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
PDF
“NPU IP Hardware Shaped Through Software and Use-case Analysis,” a Presentati...
Edge AI and Vision Alliance
 
PDF
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
PPTX
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
DOCX
Python coding for beginners !! Start now!#
Rajni Bhardwaj Grover
 
PDF
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
PDF
What Makes Contify’s News API Stand Out: Key Features at a Glance
Contify
 
PPTX
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
PPTX
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
PDF
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
PPTX
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
PDF
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
PPTX
The Project Compass - GDG on Campus MSIT
dscmsitkol
 
PDF
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
PDF
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
PDF
Biography of Daniel Podor.pdf
Daniel Podor
 
PDF
POV_ Why Enterprises Need to Find Value in ZERO.pdf
darshakparmar
 
PDF
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
PDF
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
PPTX
Future Tech Innovations 2025 – A TechLists Insight
TechLists
 
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
“NPU IP Hardware Shaped Through Software and Use-case Analysis,” a Presentati...
Edge AI and Vision Alliance
 
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
Python coding for beginners !! Start now!#
Rajni Bhardwaj Grover
 
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
What Makes Contify’s News API Stand Out: Key Features at a Glance
Contify
 
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
The Project Compass - GDG on Campus MSIT
dscmsitkol
 
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
Biography of Daniel Podor.pdf
Daniel Podor
 
POV_ Why Enterprises Need to Find Value in ZERO.pdf
darshakparmar
 
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
Future Tech Innovations 2025 – A TechLists Insight
TechLists
 

A look at FastCgi & Mod_PHP architecture

  • 1. Mod PHP and Fast CGI { { {Where did we come from? { Where are we going? Why did we need to get here? A look at FastCgi & Mod_PHP architecture [ Aimee Maree Forsstrom
  • 2. The beginning • HTML Tags – 1991 • HTML v2.0 - 1995 • HTTP v1.0 – 1996 • Computer says “213.236.210.9 Show me your home page” • Web server says “HTTP 200 OK Here you go <HTML> … </HTML>”
  • 3. Dynamic Scripts • CGI – 1993 • Receives PHP page request • Loads PHP environment • Executes request • Kills environment • Cleans it all up • Repeats for every request, yes every single one!
  • 4. Limitations • The architecture with the worst performance. Why? • Creates new process for every request • Debugging CGI scripts traditionally been difficult. Why? • Because, hard to study standard output and errors • MOD_PHP and FastCGI came about at the same time to deal with the problems of CGI [ ] • .
  • 5. Mod_PHP takes over • Apache becomes forerunner • ^ Mod_PHP gains momentum • Loads as Apache child process ^ • Preloads PHP environment • Low latency ^ • Use persistent database sessions • Shared memory • Two requests or one after the other can share memory between ^ • Store persistent data in memory (xcache, APC, etc)
  • 6. Mod|PHP the Downside • Uses Apache Permission > runs as www • Increases Apaches memory usage > Parent – Child design > need 100 apache children, if each one uses 100mb then 1GB of memory needed • Slows down Apache as Apache does the work of PHP • Apache needs to restart the child • Leads to loss of connection • Not suitable for scaling across multiple servers 
  • 7. Mod_PHP • Checks queue then parses request • Is it static? Yes/No? Either way > Apache
  • 8. How does Apache work • Procedural based parent/child design • Listener at the front • Listener places request in queue • Queue processed bottom first • Therefore, first come first served • Backend checks for new processes • Pick request from queue • Processes request returns results • Apache decides what to do with it? • PHP runs as a apache child • Therefore it can do nothing else until the script executes/times out and mark-up is delivered
  • 9. Apache gets a work-out • Backend = mod_php • Architecture leads to blocking • Apache says? • Spawn more backends • But? • We run out of memory? • Solution = limit them! • But now the queue fills up? #fail
  • 11. One + One = Two? Page load time = { PHP script load + { static load [
  • 12. Fast[Cgi takes over • Parent/Child model • Apache does not handle PHP children FastCGI does • Web servers like Apache don’t like processing applications • Web servers like dealing with static requests • Separates application from the web server ] • Web server becomes proxy server and sends PHP requests to FCGI
  • 13. Fast[CGI benefits • Preloads PHP environment • Webserver free to process static content • FastCGI handles only PHP requests • Server does not die if PHP script dies • Natively load balanced • Round robin load balancing effect • Restart PHP without restarting server • Make configuration changes on the fly _ |
  • 14. Fast[CGI ] • Apache decides if dynamic script • If yes, hands across to fastCGI • PHP load does not effect mark-up load
  • 15. Fast CGI dispatcher • Similar workflow to HTTP, but? • FastCgi is its protocol • Not HTTP • Listener takes request • Places in queue • Backends pick up • Processes results
  • 16. Fast[CGI Load Balanced • Web Server & FCGI Dispatcher separate • Dispatch among servers randomly • Dispatch among servers based on list
  • 17. how are they different? • FastCGI is interprocess communication • And mod_PHP is an in-process module Example Persistent connections Mod_php every persistent connection would own connection to the database. This can be expensive as some connections would be serving static content such as image files.
  • 18. the difference It’s the bottle neck The load is balanced in FCGI
  • 19. The future is bright • Fast CGI, but it’s old? So get into it finally! • Load Balancing • Increased Security as each backend runs as different user • Multiple PHP environment support 5.2/5.3 • Restart PHP without one dropped connection • Configuration changes without dropping connections • Not language specific • PHP runs FastCGI natively inside application • PHP compile time option
  • 20. Thank you @aimee_maree www.aimeemaree.com |