Open Source Software Technical Articles

Want the Best of the Wazi Blogs Delivered Directly to your Inbox?

Subscribe to Wazi by Email

Your email:

Connect with Us!

Current Articles | RSS Feed RSS Feed

mod_php vs. FastCGI vs. PHP-FPM for Web Server Scripting


Most administrators know that PHP, the widely used scripting language, can be embedded in HTML and works with all major web servers. What's less widely known, however is that you can run PHP in different ways on your server. The most common option is the mod_php module that's runs by default in the Apache HTTP Server. If your primarily goal is performance, however, you should consider other options. PHP-FPM (FastCGI Process Manager) and PHP FastCGI each have pros and cons, but either can speed up the performance of your PHP.


Let's start by looking at running Apache with mod_php. This package is present in just about every Linux distribution's repository, so installing it is easy, and so is configuring and managing the software. In fact, its ease of use may be the main reason to deploy mod_php.

PHP accelerators

Using a different PHP package isn't the only way to improve PHP performance. PHP accelerators, also called opcodes cachers, increase the performance of PHP applications by caching the compiled form of PHP scripts. A PHP accelerator typically reduces server load and increases the speed of your PHP scripts as much as 10 times depending on how many different pages and PHP scripts are used and cached. While you can find several PHP accelerators, my suggestion is to use APC (Alternative PHP Cache), an opcode cache maintained by the developer of PHP, who plans to integrate it into PHP starting in version 5.4.

To see how APC helps speed PHP, let's look at how a PHP program is run.

  1. The first step is reading the PHP code from the filesystem and put it into memory.
  2. In the lexing step, PHP code is converted into tokens or lexicons.
  3. In the parsing step, tokens are processed to derive meaningful expressions.
  4. The derived expressions are compiled into opcodes.
  5. Opcodes are executed to get the final result.

The goal of APC is bypass steps 1 to 4 for each call after the first one, instead caching in a shared memory segment the opcodes generated and then copying them into the execution process. APC is easy to install and configure, so I suggest using it in every PHP installation.


With mod_php the PHP interpreter is "embedded" inside the Apache process; Apache doesn't call any external PHP process, which means that Apache and PHP can communicate better. However, every single Apache child must load mod_php, which results in a bigger process than necessary being used for serving static resources such as image files, CSS, and JavaScript.

Another problem with this method is that it works only on Apache. This is not always an issue, as Apache is the most complete web server you can find, but websites that run on small virtual private servers (VPS), or big sites that have to serve million of pages a day, might want a different web server that can scale up or down better than Apache, and would therefore need a different way to run PHP too.


  • Easy to install and update.
  • Easy to configure with Apache.


  • Works only with Apache.
  • Forces every Apache child to use more memory.
  • Needs a restart of Apache to read an updated php.ini file.



FastCGI is a generic protocol for interfacing interactive programs with a web server. It's a variation on the earlier Common Gateway Interface (CGI) that reduces the overhead associated with interfacing the web server and CGI programs, allowing a server to handle more page requests at once.

Apache can use FastCGI in the form of mod_fcgid, and other popular webservers, such as lighttpd, nginx, Cherokee, and even Microsoft IIS, can use FastCGI as well.

With FastCGI you can set up multiple versions of PHP. This is particular useful when you have old websites made for, say, PHP 5.1 that are not compatible with the latest version of PHP. With FastCGI you can serve old PHP to the old website while using the latest version for all the others, something that is not possible with mod_php.

FastCGI also utilizes suexec to support different users with their own instances of PHP. This feature is particularly important for improving security in a shared environment, where you could have different users each managing their own websites. FastCGI reduces the memory footprint of your web server, but still gives you the speed and power of the entire PHP language.


  • Compatible with many web servers.
  • Smaller memory footprint than mod_php.
  • More configuration options, including multiple PHP and suexec.


  • Requires more configuration than mod_php.
  • Not widely known in the IT community.


PHP-FPM, the newest way to use PHP with a webserver, is an alternative PHP FastCGI implementation with some additional features that can be useful for websites that run on both small VPSes and multiple servers. It can be used with any web server that is compatible with FastCGI.

PHP-FPM gives administrators the ability to gracefully stop and start PHP worker processes without losing any queries. This allows you to gradually update the configuration and binary without losing any queries. You can start workers with different uid, gid, and chroot environments and different php.ini options. You can also run an emergency restart on all the processes in the event of any accidental destruction of the shared memory opcodes cache, if you're using an accelerator.


  • Compatible with many web servers.
  • Smaller memory footprint than mod_php.
  • More configuration options than FastCGI.


  • Requires more configuration than mod_php.
  • Not widely known in the IT community.
  • Project is still relatively young.


I can think of no general rule or guideline to tell you what's the right method for you or your company to use to speed up PHP. Personally, I use mod_php on most servers for its stability and the fact it is so well-known. I use PHP-FPM on small VPSes where saving memory while keeping fast performance is a must. The important thing to keep in mind is the variety of different solutions available; knowing about all of them is fundamental when planning your project.



This work is licensed under a Creative Commons Attribution 3.0 Unported License
Creative Commons License.


Do you know of any benchmarks that support these claims. Running a test with apache bench on a machine with both mod_php and php-fpm installed, mod_php was 20% faster.
Posted @ Thursday, November 01, 2012 4:20 PM by Derak
I agree that mod_php is faster than php-fpm but I use php-fpm because I need security in shared hosting environment.
Posted @ Sunday, March 31, 2013 3:53 AM by Crane
Nice article explaining the most used options for running PHP. I'd like to add that mod_php will use less memory in a shared hosting setup than FastCGI, for the simple reason that every site will have it's own PHP processes. It really depends on how many sites you want to run. I'm thinking that the best of both worlds would by to run mod_php/apache for the php and Nginx to handle all the static content (by using nginx as a frontend proxy)
Posted @ Sunday, June 02, 2013 4:45 AM by Barry van Someren
It's actually pretty simple, if you're running high traffic web servers or php heavy applications such as Drupal, go with FastCGI or PHP-FPM. Running mod_php on such servers will easily run them OOM to such extend that the server because completely unusable.
Posted @ Sunday, September 22, 2013 3:39 AM by Bram Pieters
Great article
Posted @ Wednesday, February 12, 2014 5:51 AM by Foxinni
Buy replica purses from online wholesalers. There are abounding altered websites that action above artist purse replicas and will acquiesce you to buy accoutrements in aggregate at a discounted rate. See the ability area beneath to louis vuitton replica go to a website that sells handbags for you to acquirement in bulk. Consistently aim to advertise the purses for added than you paid for anniversary of them in adjustment to accomplish a profit. Replica Rolex Watches Rolex Replica, Cartier Replica, Breitling Replica, Gucci Replica, Omega Replica, Louis Vuitton Replica, Porsche Architecture Replica, Tag Heuer Replica and abounding more. You can adore the aforementioned address and breeding of the replica watches aboriginal cast name watches at actual affordable price. Rep1ica is a able aggregation specialized in affairs replica watches of the a lot of replica shoes accepted brands. Our ambition is to accommodate chump the top superior watches at the everyman price, so alone works with the a lot of reliable and accomplished replica articles who committed in authoritative the finest replicas to accommodated clients' appeal both in aboriginal architecture and material. Our aggregation monitors and inspects anniversary artefact from accomplishment to packaging, to gucci replica ensure that anniversary chump receives a able product. With affluent acquaintance of carrying watches to our barter worldwide, abnormally in Europe, America and Oceania, has the adeptness to forward the ordered watches cautiously to its barter with simple means to bright the customs. As for the watches, can accommodate a lot of rolex replica the acclaimed watch articles all over the apple which include: Rolex, Breitling, Bvlgari, Cartier, Chanel, Corum, IWC, Gucci, MontBlanc, Omega, Tag Heuer, and More! The aboriginal watches are originally advised by today's aristocratic craftsmen and after-effects in the big-ticket prices as they are apparent beneath acclaimed cast names.
Posted @ Saturday, September 13, 2014 2:23 AM by xixi
Tactical watches must be able to survive the harshness of the outdoors and they are waterproof. Straps must be proof against dirt and is low-maintenance or if possible doesn't have any maintenance by any means. Some have rubber straps which are cheap but tough whilst others have canvass straps that keeps program the total look and color of tactical Swiss replica watches. The sole drawback both of these sorts of straps have is they might have a distinct smell when they are not kept dry. The watches have illuminated displays for telling time in low-light situations or in the evening. The analog types normally have dials and displays with luminous paint but tend to be impractical for your constant glow can provide away the position of the soldier. 
The digital type includes a light that could be triggered manually thus are definitely more trusty cheap replica watches uk. Military men prefer to have a very 24-hour time display. Digital field watches can become a 24-hour display with no trouble while analog watches have another indicator scale that shows thirteen to twenty-four that corresponds towards normal that you twelve scale. Watches aren't suitable with any business settings because they would desire more formal sorts of watches. His or her don't choose the suit! Wearing tactical watches towards the CEO meetings is compared to attending a black-tie dinner wearing work boots! 
They are not just proper for formal venues. These replica watches are meant for those who are active and always out and about. The military watches will restrict for military personnel use but can be worn are by fashion, extreme sports fans or by those urban warriors Cheap Replica Watches. The military watches in the present day can be obtained with an increase of fashion flair and several versions are offered. The inbuilt toughness these watches means they are ideal for extreme sports and their specs make them only the thing for gadget freaks and urban warriors prefer them because of their cool look, excellent for that street look.  
Posted @ Friday, September 19, 2014 4:39 AM by Lams
Where you should acquire hermes belt system burberry store retailer inside british guys oakley snowboarding eye protection selling hermes belt dimensions ninety days burberry <strong>fake watches</strong> trial selling 2012 british ray bar wayfarer sun shades artificial oakley prescribed sun shades inserts burberry store san marcos arizona ray bar aviator regarding huge confronts ray bar manufacturing facility store melbourne are usually burberry umbrellas excellent erika <strong>fake Audemars Piguet</strong> kors i phone 5 bag british louis vuitton ellipse mm ceased burberry look-alike headscarf selling artificial louis vuitton hand bags on the market philippines oakley sun shades retailer artificial louis vuitton carrier acquire ray bar sun shades clubmaster metal low-cost hermes diamond british acquire hermes <strong>fake IWC</strong> diamond on the web hermes europe charitable organization cotton selling hermes nevada encore hermes carrier value 2013 malaysia just how timepieces are usually ray bans thus low-cost about craigs list traditional louis vuitton bags philippines hermes birkin carrier store british ray bar substitute contact lenses value louis vuitton retailers nevada low-cost burberry child umbrella oakley radar spectacles low-cost.
Posted @ Saturday, September 20, 2014 3:29 AM by fake watches
See here the best edges and finish relating to the hands and applied prints, the dual-level date windowpane bevel and split tiny ring. Also see the two-color resale and subtle Breitling inset towards the minute markers. Really nice and well considered design here. Note also the subtle usage of 'signal yellow. ' The tip in the second hand, '2000 meters' text, minute markers too and also minute hand matching this bezel. Not sure what I presume of the retro font to the lower half of this dial, but it works to provide a piece. Add a thousand approximately for the bracelet and it goes up to retail price of cheap - which I'd hunt for if I were buying one today. Look around for whatever you can fine. There are a small amount of color variations, and the piece is also offered in chronograph develop. I have no doubt about recommending the Breitling. This is a superb watch, full stop. Due to the caseback pattern, it sits quite low and comfortable within the wrist, and doesn't flop about like some taller watches We've worn. The double AR not to mention domed crystal combine to get stupendous visibility at quite a few angles. You can also observe that Breitling uses a vertical black flange ringe; functional and invisible replica breitling. The angled Breitling models to illustrate is one of great pet peeves of flange arena design. Not an issue here with this Breitling. Think of the significant lefty triggered Breitling see. For the Breitling gave their watch a unique treatment, but adding dauphine design hands, that are usually available on more "formal" timepieces. I suppose it wants to so with the Breitling community fake watches. Breitling also says the fact that the hands look like the points at the Breitling three-pointed star. What is 100% Breitling certainly is the design of the part chronograph dials. There is also the similar Breitling fake omega watches, which has a corresponding, but amended style, along with a completely different movement layout. 
Posted @ Saturday, September 20, 2014 4:38 AM by sonades jackson
I was considering going with fastCGI because i am having the odd OOM error on my vps using mod_php with 1GB Ram, and that knocks off the server for way to long. I make sure i reboot my server using cron every six hours but sometimes if it is in the OOM phase it cant fork so it loops like that for a while until i fix it or it finally reboots.
Posted @ Wednesday, October 15, 2014 10:56 AM by Phpman
Post Comment
Website (optional)

Allowed tags: <a> link, <b> bold, <i> italics