PHP-FPM Cuts Web App Loading Times by 300%

by Immad Uddin Khan  August 23, 2016

Speed matters. Our engineers are always looking at ways on improving the stack. One of the major objectives of our stack integrations is to improve the speed of the overall processes of our stack.

Keeping up with this practice, in a bid to increase speed of aspects of Managed Cloud Hosting coupled with constant improvements based on users feedback, Cloudways has now integrated PHP-FPM in all its servers. Owing to this integration, applications hosted on Cloudways servers are now going to perform up to 3x faster.

Why PHP-FPM?

From a website visitor’s perspective, switching from mod_PHP to PHP-FPM might not be much of a bigger deal. However, from a system administrator’s point of view, both of these are entirely different things.

All system administrators are aware that PHP works with all major web servers and it can be run in different ways on your server. One of the most common known ways to run PHP is the mod_php module. This is because it comes by default on the Apache HTTP servers. But there is a slight problem. Unlike PHP-FPM, mod_PHP locks out processes and disrupts the performance of a website.

If your primary goal for hosting your web application with an optimized cloud service is to achieve optimal performance and security, then PHP-FPM is the way forward.

PHP-FPM (FastCGI Process Manager) dramatically speeds up the performance of your PHP environment.

PHP-FPM vs. mod_PHP Performance Benchmarks

Using a controlled environment we tested a WordPress website using both PHP-FPM and mod_PHP. We have not used Varnish or Turpentine for the test. Each time, we noticed increased performance and stability with the stack that contained PHP-FPM.

Performance with mod_PHP

We used a DigitalOcean 4 GB server. The app for this test was a WordPress website.

wordpress-mod-php

Test generated 38,046 successful hits in 295.0 seconds with a data transfer of 7,399.11 KB in and 206,219.42 KB out from the app. The average hit rate of 128.0/second translates to about 1,1059,200 hits/day.

The average response time was 2150 ms.

Performance with PHP-FPM

The only thing different in this test is the addition of PHP-FPM.

wordpress-php-fpm

Test generated 85,829 successful hits in 295.0 seconds with a transfer of 16,465.18 KB in and 465,728.74 KB of data out from the app. The average hit rate of 290.0/second translates to about 25,056,000 hits/day.

The average response time was 628 ms.

Results

You can notice PHP-FPM made our test website almost 350% faster when it comes to loading times. Plus, it made the site twice as resource efficient as it was with mod_php.

PHP-FPM, one of the newest way to use PHP in conjunction with a web server, is an alternative PHP FastCGI implementation. This module of PHP can be used with any web server which is compatible with the protocol of FastCGI.

The major advantage of PHP-FPM is that it relies on the concept of pool management. Each pool of PHP-FPM can be viewed as a full instance of PHP, having a configuration, limit and restrictions of its own. These limitations, restrictions, and configurations are in terms of the child processes, modules, environment variables, folders, and logs.

How to Enable PHP-FPM?

For servers launched after this announcement dated August 23rd, 2016, PHP-FPM has been enabled by default. For new server instances, mod_PHP has been retired by default. For servers launched before August 23rd, you can enable PHP-FPM by going over this step-by-step guide.

PHP-FPM vs. mod_PHP: Which is Better?

We believe that it is really not a matter of PHP-FPM vs mod_PHP. With this move, we are targeting the main aspects Cloudways aspires to achieve: Reliability, Security, Scalability, and Speed. PHP-FPM provides all these along with a lot of customization and performance tuning opportunities. Therefore, it is only feasible that we move from slower processes (mod_PHP) to much faster processes with PHP-FPM.

Start Creating Web Apps on Managed Cloud Servers Now

Easy Web App Deployment for Agencies, Developers and E-Commerce Industry.

About Immad Uddin Khan

Immad is a Digital Content Producer for Cloudways - A Managed Cloud Hosting Platform. He is mostly busy in creating all sorts of informative and innovative content types. As a hobby, he loves to travel with his camera to picturesque destinations.

Stay Connected:

You Might Also Like...

  • Scott

    Amazing! You guys and gals are making some awesome improvements! Keep up the great work.

  • Halleleujah!

  • This is great news. I’ll consider to move to Cloudways, keep up the good work and focus!

    • Thanks Vegard, More great features are yet to come 😉

  • mblair

    With your PHP-FPM configuration, does this least to any increases or decreases in typical RAM requirements that may impact the smaller DigitalOcean instances like 512k and 1GB? Can the PHP-FPM configuration be tuned within the Cloudways options for a particular server?

  • What is the load testing app you’ve used? I’m sure if seen it before but cant remember the name of it

  • Wilfred Ling

    After I received the email from Cloudway on this PHP-FPM this morning, I install it and now my server crashed. As I wait for Cloudway to fix it, I am losing customers. The lesson is: Never be too fast to try new things.

    • Brian O’Neill

      Out of curiosity what app were you running? WordPress?

      • Wilfred Ling

        Apparently Cloudways script was buggy resulting in certain software not installed for Apache. My server was running php script and WordPress and both couldn’t work due to Apache unable restart. The guys at Cloudways resolved the issue eventually but after a downtime of nearly 3 hours. I suggest you guys NOT to install it until they have fully resolve the issue.

        As a side note, I discovered server cloning to be full of bugs. Out of desperation I cloned my server hoping the cloned server will work but it did not as almost all the server settings were not cloned. It seems the process of cloning is a mere copying of all the application data to a new server whose settings can be vastly different from the original one.

        • Hi Wilfred,

          Sorry to hear about your experience, we have thousands of servers and applications running, each vastly different from one another. We did our best to keep every configuration bug free, we worked with clients to resolve issues that came up out of the blue.

          The best way to upgrade to newer “Server Side” changes is to clone your server and cross check everything before upgrading your current site.

  • Can there be any wp plug-in compatibility issues when running php-fpm? Thanks.

    • Hi,

      There aren’t any known compatibility issues with PHP-FPM and WordPress plugins. But if you have a plugin that makes changes in the .htaccess then it is better to check before making the upgrade.

      • Tevya Washburn

        This is my biggest concern. Plugins like iThemes Security rely HEAVILY on .htaccess to do things like change the login url, force SSL on the front and back end, implement lockouts and blacklists, and all kinds of stuff. How can these plugins work without an .htaccess file? I’m really confused. It seems like there would either be tons of problems and lots of people complaining, or a simple answer. But I can’t seem to find an answer to this.

        • Hi,

          With the addition of PHP-FPM in our ThunderStack, all the PHP executions are now handled by PHP-FPM. So, if your .htaccess file are resulting in changing PHP Settings on runtime you will get a 500 error. This is because now Apache doesn’t handle PHP executions any longer. Except for PHP Settings all other URL rewrite rule will work with .htaccess. So, If your plugin is trying to change the PHP Settings on runtime, you will be prompted with a 500 error automatically.

          To remove this error, you need to define these settings in PHP-FPM pool. Cloudways had made it easy for you. Simply navigate to your Application Settings and then select PHP Settings tab. Now, paste the PHP Settings that are defined in the .htaccess file in the PHP FPM Settings Editor. Make sure the format is correct. For your convenience, we have provided an example code format.

          • Tevya Washburn

            Ah. Thanks for explaining. I don’t think we’re doing any php settings in htaccess. So I think we’re good. Thanks again.

  • “Any PHP directives defined in a .htaccess will not be used.” So I need to back up my ..htaccess first and rewrite after I upgraded to PHP-FPM?

  • Axiom Online

    I have upgraded to PHP-FPM today and would recommend the following procedure:

    The safest way forward:

    – 1st disable any security, hardening, bot blocking and htaccess related plugins on your current live site, especially Wordfence!! The only site that had this running got an unrecoverable white screen and a boat load of errors (via logs). To resolve, I had to migrate using CW’s tool to a new application instance on the new server to get around it.

    – I recommend cloning your server rather than doing an in-place upgrade (Your new server will automatically have PHP-FPM enabled AND if you use Vultre you will get 10gb or more extra disk space bonus based on the new tariffs 😉

    – Remember to compare and update your Cloudways server settings on the new cloned server, as they all revert to ‘default settings’.
    SETTINGS & PACKAGES > ‘Basic and Advanced’ tab.
    If you have updated your PHP version and/or db in the past to latest Mysql or Mariadb, it will go back to the default state which will cause issues for sure.

    – Add your domains and subdomains back in APPLICATIONS > DOMAIN MANAGEMENT (basically check and copy settings from your original server and then delete in original server once complete.

    – And finally update your DNS to reflect the ‘New Server IP’ and ‘New Application Name’ e.g wordpressmu-xxxxx-xxxxx-xxxxxx.cloudwaysapps.com

    PS: I would keep the original server for a couple of days before you delete it, incase you missed something and needed to double check.

    I know it’s tempting to hit the upgrade button straight but glad I did not. I don’t play Russian roulette on client sites from experience 🙂

    Happy days !!

    • Hi Axiom,

      Thanks for taking time to share your precautionary steps and upgrade guide with rest of the Cloudways clients. I second your recommendations. 🙂

  • Hello, Support WP?
    Regards.

    • Hi Marcelo,

      Yes, Cloudways has WordPress available as a one click installation on all the four cloud providers we support. And yes, PHP-FPM works well with WordPress.

  • ninsky

    The new PHP-FPM seems to break HTTP digest authentification. Doesn’t work any more (always getting a 401 response; but same code works on mod php on dev). Could the reason be a missing config on Cloudways? (see http://stackoverflow.com/questions/7884687/http-authentication-with-php-running-as-fcgi). Anyone experiencing similar issues?

    • Immad Uddin Khan

      @ninsky80:disqus Please open a Support ticket so that our customer support experts can look into this.