PHP-FPM, when speed counts!
Team Host.it 5 min read
Content
The hosting offer that we present to our Customers and Partners is designed to adapt to the real needs of the project to be developed, grows when necessary and, every year, is enriched with new features and technological innovations.
Today we are talking to you about a technology that has been available within our hosting profiles for several years: PHP-FPM. But, let's take a very small step back to explain how we previously managed all the php requests made by users to your sites hosted on Host.
Most site administrators (those who develop and manage them) know that PHP, one of the most used scripting languages in the world, can be embedded in HTML and works with the main web servers. However, the least known aspect is how PHP can be executed on the web server, and this can happen in several ways.
Let's make a small parenthesis to explain how our platform is made up. If we used the acronym LAMP, how many people know what we are talking about? For those who don't know, here's a very brief definition:
"LAMP is an acronym that indicates a software platform for the development of web applications which takes its name from the initials of the software components with which it is created:
Linux (the operating system) Apache (the web server) MySQL or MariaDB (the database management system) HP (the programming language)
The LAMP platform is one of the most used worldwide. Each of the applications from which it is composed is designed for excellent functioning in conjunction with the others." [Wikipedia]
The way we ran php requests and processes on our LAMP platform was PHP FastCGI . Let's take a quick look at how it works together. This is a generic protocol for interfacing with a web server. Specifically, it is a variant of the previous Common Gateway Interface (CGI) which aims to reduce the overhead associated with interfacing between web servers and CGI programs, allowing a server to handle multiple requests simultaneously.
With FastCGI you can configure multiple versions of PHP, especially useful when you have old websites created, for example, in PHP 5.1 that are not compatible with the latest version. Finally, with FastCGI it is possible to support different users each with their own instances of PHP. This feature is especially important for improving security in a shared environment, where you may have different users each managing their own websites.
How does FastCGI work? Thanks to the PHP FastCGI protocol, the webserver generates a single process in the initialization phase which, at the end of the start-up phase, waits. Every time a new incoming request arrives, the webserver opens a connection with the fast-cgi process (waiting) which in turn generates the output on the connection with the client, transferred to it by the server. The main advantage of this protocol is the creation of processes only during the initialization phase, thus optimizing the number of php processes.
What changes with the introduction of PHP-FPM? PHP-FPM is a more recent way of using PHP with a web server, and is an alternative to the previous PHP FastCGI with the implementation of some additional features that are very useful especially for sites that manage more and more traffic every day (from showcase sites to e-commerce). For these types of websites it is therefore necessary to have increasingly high-performance tools available, just like PHP-FPM.
The operation is very similar to PHP FastCGI and is always based on the optimized execution of PHP processes which are created only during the initialization phase and remain waiting for a new request. The big difference is that it is the PHP-FPM (FastCGI Process Manager) itself that executes the process and no longer the web server.
The "Process Manager", as the name suggests, is a script that directly manages PHP processes. It waits for and receives instructions from the web server and executes the required PHP scripts and allows a website to handle heavy loads. The PHP-FPM maintains "pools" to respond to PHP requests and the processes that are generated are directly "children" (CHILD) of the Process Manager and can therefore be managed separately from the web server.
This mode guarantees greater robustness of the service, since operations such as configuration changes or restarting processes impact the individual FPM pools and no longer the entire web server.
Let's now look at some of the technical features of PHP-FPM: Demonization of PHP processes (PID files, log files, setsid(), setuid(), setgid(), chroot();
Ability to restart PHP processes without causing any interruption of requests during processing, you can therefore change any parameter in the configuration file or even update PHP without even 1 second of downtime!;
Possibility of not processing requests coming from a specific IP;
Ability to start CHILDs under different UID/GID/CHROOT and with different PHP settings (php.ini) all without the need for safe mode;
Ability to log via stdout and stderr;
In case of corruption of the shared RAM used by an OPCode Cache, PHP-FPM can perform an emergency reboot of all PHP CHILDs;
Forces script execution to stop if set_time_limit() fails.
Finally, in order to guarantee security and speed to your websites hosted on the Host platform and to encourage you to update your CMS, PHP-FPM is available only and exclusively starting from version of PHP 7. After several implementation tests, we have in fact preferred to make this technology available to those who have updated their version of PHP to the most recent one precisely because the combination of PHP 7 (and subsequent versions) and php-fpm guarantee greater performance in terms of security and response speed.
In fact, let us remember that one of the ways to guarantee maximum security for your websites and applications is to keep them constantly updated.
In this way you can guarantee an increase in performance, security and, consequently, have a successful site for your online business.
PHP-FPM in numbers: some data on speed As we have explained at length, PHP-FPM speeds up the performance of a PHP environment. But what kind of increase are we talking about? Let's see together the result of some tests to better understand how much the response speed of websites really increases with the implementation of PHP-FPM.
The test was performed by comparing the performance of PHP FastCGI (with PHP 5.6 version) vs PHP-FPM (with PHP 7.2 version) for loading the homepages of a site in WordPress, one in Joomla! and one in Prestashop.
E-commerce
Hosting for online stores
PrestaShop, WooCommerce and Magento: performance, security and datacenters in Italy.
Related articles
From the archive