PHP-FPM (FastCGI Process Manager) is the most popular alternative implementation of PHP FastCGI. PHP (acronym of PHP: Hypertext Preprocessor) is one of the most popular open source programming languages on the Internet, used for web development in platforms such as Magento, WordPress or Drupal. Although it was initially designed for preprocessing plain text in UTF-8.
PHP, created by Rasmus Lerdorf in 1995, was one of the first languages that could be included in HTML code, without having to call external files. This general-purpose scripting language on the server side has constantly evolved so that it can be supported by any operating system or web platform. Furthermore, PHP keeps evolving and is published under the PHP licence, which is incompatible with the GNU General Public License due to use restrictions of the PHP term.
What is PHP-FPM and its features
PHP-FPM is the most popular alternative implementation of PHP FastCGI. It has additional features which are really useful for high-traffic websites. These are some of them:
- Advanced management that enables to easily stop/start processes.
- Possibility to start workers with different uid/gid/chroot/environment and diverse php.ini; it replaces safe_mode.
- Stdout and stderr logging.
- Emergency restart in case of accidental destruction of the opcode cache.
- Accelerated support for uploads.
- Slowlog variable configuration; to detect which functions take a longer time to execute than usual.
- Based on php.ini configuration files.
- FastCGI improvements, as fastcgi_finish_request(); a special function to stop and download all data while you keep doing a longer process such as video conversions or statistics processing.
- Basic statistics (similar to Apache’s mod_status module). NEW!
Nginx and PHP-FPM: a perfect match
Nginx as stable high-performance web server, and with a very low consumption of resources, is the perfect match for PHP-FPM. Nginx has an asynchronous architecture that is much more scalable, based on events. Moreover, when using Nginx with PHP-FPM, performance at the level of memory consumption is improved.
PHP runs as a separated service when using PHP-FPM. By using this PHP version as language interpreter, requests are processed through a TCP/IP socket; so that the Nginx web server only handles the HTTP requests and PHP-FPM interprets the PHP code. The fact of having two separate services is key for increasing efficiency.
HHVM: a former alternative to PHP-FPM
Currently, HHVM is no longer in use. With the arrival of the last PHP version together with FPM, the performance of this language has been equaled, or even improved, without the need of using HHVM — compatible with most of the functions of PHP 7.
Until the arrival of PHP 7, the PHP HHVM processor developed by Facebook and released on GitHub with PHP and Zend licences was often used. HHVM (HipHop Virtual Machine) is an open source virtual machine based on the JIT (Just-in-Time) compiler, which serves as an execution engine for PHP and Hack.
By using the JIT compiler principle, HHVM executes PHP or Hack code in intermediate Bytecode HipHop code; a code which is later translated into machine code, natively optimized and executed. This contrasts with the usual interpreted execution of PHP where the Zend Engine transforms PHP source code into opcode (bytecode form); which is executed by the virtual CPU of Zend Engine.
PHP 7 and future versions of PHP
The arrival of PHP 7 involved a great increase in performance compared to previous versions of PHP. This made that applications such as HHVM, which were used to accelerate services, fell into disuse. In this PHP comparator, you can view the differences among the diverse versions of PHP for several applications. The comparative chart shows how performance has been almost doubled since PHP 5.
For the next major version, PHP 8, the development seems to be focused on creating new functionalities instead of considerbly improving speed. So, in order to avoid the application to stop working after the update, the compatibility between the applications and the changes included in the new version must be considered when updating.
WordPress with PHP-FPM
If you have a content platform, online newspaper or, simply, a WordPress that needs high performance and receives thousands or millions of visits, it is evident that you need a Nginx server with PHP-FPM support. This will allow you to set up the execution of PHP code of your WordPress CMS much more efficiently.
Magento with PHP-FPM
The eCommerce platform Magento also integrates well with Nginx and PHP-FPM. In fact, in order to achieve the best performance in your online store, apart from using balancers and caches, it is key to use this popular web server together with support for PHP-FPM.