DEV Community

Cover image for PHP: FPM | FastCGI | mod_php
Tahir Raza
Tahir Raza

Posted on

PHP: FPM | FastCGI | mod_php

PHP, a widely spread scripting language mainly used for websites or more specifically backend web development. You might have heard these terms mentioned in the title of the post but if you are someone like me, then you probably don't fully understand these things.

So todays post will be more about the definitions, conceptual differences and pros/cons for one over the other.

Whenever I want to learn something new I follow some simple steps:

  1. Understand the meaning/definition of the new term
  2. Learn about the history
  3. Learn with examples and/or learn with alternatives

So let's try to follow this approach.

PHP

Meaning/Definition

PHP, originally extracted from Personal Home Page Tools, now stands for PHP: Hypertext Preprocessor.

History

Rasmus Lerdorf is the guy who created of PHP and Andi Gutmans and Zeev Suraski are the creators of the Zend Engine.
You can read an in detail historical background on the wiki page if you like but the interesting fact is PHP's first version was released way back in June 1995. Yes it's that old.

Example Usage

PHP executes on the server, while on the hand JavaScript executes on the client.
PHP is mostly used for backend web development but it is also fully capable to make command line applications.

Now as you know that PHP runs on the server, you may ask what servers? how does a server know how to run PHP? And that's where the mod_php, fastCGI and FPM comes into picture.

First things first, let's understand a few terms.

  • mod_php: Module PHP
  • CGI: Common Gateway Interface
  • FastCGI: Fast Common Gateway Interface FastCGI is a binary protocol for interfacing interactive programs with a web server. It is a variation on the earlier Common Gateway Interface (CGI).
  • FPM: FastCGI Process Manager

Ok so now you at least know the definitions of acronyms.

Today we will look into two different ways to run PHP on a server and there are two very well known backend servers used to run PHP Apache and Nginx.

So to run PHP on these servers there are two ways:
You can run PHP as a module in Apache server (mod_php) or you can run PHP as an independent process (PHP FPM) and configure the server to use the process to handle PHP files.

A simple google search ("php fpm vs mod_php") will give you a lot of good resources on how to configure these two and what are the benefits of one over the other but there are key differences I would like quickly share with you:

  • PHP FPM is way faster then mod_php
    mod_PHP locks out processes and disrupts the performance of a website

  • HTTP 2 Support
    If you want HTTP 2 support you should go with PHP FPM as mod_php does not support it.

A more detailed and in my opinion more accurate reading on this is a stackoverflow answer, please read here if you are interested.

Top comments (0)