Mod_php, FastCGI, PHP-FPM and other PHP Running Mode Comparison
This article mainly introduces mod_php, FastCGI, PHP-FPM and other PHP Running Mode Comparison, this article explains what is PHP processor (PHP handlers) mod_php advantages and disadvantages, FastCGI advantages and disadvantages, PHP-FPM (FastCGI Process Manager) Advantages and Disadvantages of other content, need friends can refer to the next
Overview
I wrote this article because I want to build the LNMP environment under Ubuntu today, Nginx uses a PHP-FPM, so the interaction between the Web server and the PHP interpreter is organized.
As we all know, PHP is a cross-platform and cross-server language, which is also one of the reasons for its popularity. However, few people know that the PHP interpreter can run on the Web server in different ways. The most common method of PHP is to run the module (mod_php) in Apache, which is also the default method for Apache to run PHP. However, in Nginx, Nginx uses PHP-FPM again.
This article will introduce these concepts. If there are any mistakes, please criticize and advise them a lot.
What is PHP handlers )?
Remember that any Web server (such as Apache and Nginx) is designed to send html, images, and other static resources to users, the Web server itself cannot interpret any dynamic scripts (such as PHP and Python ). The PHP processor is used to explain the PHP code in a Web application, interpret it as HTML or other static resources, then pass the parsing result to the Web server, and finally send it to the user by the Web server. Most Web servers cannot parse PHP code, so they need a program that can parse PHP code. This is the PHP processor.
Mod_php
First, let's take a look at running PHP using the Apache module. Mod_php is now available in various Linux software repositories, so it is easy to install.
When PHP runs in Apache as a module, the PHP interpreter is "embedded" in the Apache process. Apache does not call any external PHP process, so this method enables better communication between Apache and PHP. However, when running PHP in this way, even if Apache only provides static resources (such as HTML), every sub-process of Apache will load mod_php, this causes more memory overhead than normal.
Another disadvantage of running in this way is that it can only work with Apache. In addition, this method is not suitable for small VPS and large websites, because large websites may have a lot of static resources which do not need to be explained by PHP programs.
Advantages:
1. easy to install and update
2. Capacity Configuration
Disadvantages:
1. Work with Apache only
2. added memory overhead for Apache sub-Processes
3. After changing the php. ini file, restart Apache.
FastCGI
FastCGI is a Common protocol Interface between interactive programs and Web servers. It is a variant of early CGI (Common Gateway Interface. Compared with CGI, FastCGI reduces the overhead of interaction with the Web server and can process more requests at the same time.
Apache can use FastCGI in the form of mod_fcgid. FastCGI can be used on other Web servers, such as lighttpd, nginx, Cherokee, and Microsoft IIS. With FastCGI, you can set multiple PHP versions at the same time, which is useful in some cases.
FastCGI also uses suexec to support different users using their own PHP instances. This feature is especially important for improving security in a shared environment. FastCGI reduces the memory overhead of the Web server while ensuring performance.
Advantages:
1. compatible with most Web Servers
2. Smaller memory than mod_php
3. More configuration items, including PHP and suexec
Disadvantages
1. complicated configuration
2. Not well known
PHP-FPM (FastCGI Process Manager)
PHP-FPM is the latest way for Web servers to use PHP, and is also another Implementation of PHP FastCGI. PHP-FPM is very useful for Web applications running on small VPS and on multiple servers. It can also be used by any Web server compatible with FastCGI.
The PHP-FPM enables administrators to gracefully stop and start PHP workflows without losing any queries. This allows us to gradually update the configuration and binary without losing any query. It also allows us to restart the process in case of any unexpected damages.
Advantages:
1. compatible with most Web Servers
2. Smaller memory than mod_php
3. More configuration items, including PHP and suexec
Disadvantages
1. complicated configuration
2. Not well known
Supplement: four ways for Apache to run PHP
Mod_php (DSO, Dynamic Shared Object)
CGI
SuPHP
FastCGI
Summary
The content is relatively abstract and not deeply understood. record it for future reference ~ :)