How is php-fpm better than php being an apache module?

How is php-fpm better than php being an apache module?

Nianhua 81kgPS61  |  Browse 1896 times | Report
I have a better answer
 
Recommended on 2017-11-23 10:46:09 Best answer
 
Overview 
  This article is written because today I want to build an LNMP environment under Ubuntu, and Nginx uses PHP-FPM, so I have sorted out the interaction between the Web server and the PHP interpreter.
  As we all know, PHP is a cross-platform, cross-server language, which is one of the reasons why it is so popular. However, few people know that the PHP interpreter can be run in a web server in different ways. The most commonly used way of PHP is to run in Apache as a module (mod_php), which is also the default way for Apache to run PHP. But in Nginx, Nginx uses PHP-FPM.
  This article will introduce these concepts. If there is something wrong, please criticize and give advice.
  What are PHP handlers?
  The first thing to remember is that any kind of web server (Apache, Nginx, etc.) is designed to send static resources such as html, pictures, etc. to users, and the web server itself cannot interpret it. Any dynamic script (PHP, Python, etc.). The PHP processor is used to interpret the PHP code in the Web application, and interpret it as HTML or other static resources, and then transmit the parsed result to the Web server, and finally the Web server sends it to the user. Most web servers can't parse PHP code, so it needs a program that can parse PHP code, which is a PHP processor.
  mod_php
  First, let's take a look at running PHP as an Apache module. mod_php is now available in the Linux distribution repositories, so it is easy to install.
  When PHP runs as a module in Apache, the PHP interpreter is "embedded" in the Apache process. Apache does not call any external PHP process, so this way Apache and PHP can communicate better. However, when running PHP in this way, even if Apache is serving only static resources (eg HTML), mod_php will be loaded by every child process of Apache, resulting in more memory overhead than normal.
  Another disadvantage of running it this way is that it only works with Apache. In addition, this method is not suitable for small VPS and large websites, because large websites may have many static resources, and these static resources do not need to be interpreted by PHP programs.
  Advantages:
  1. Easy to install and update
  2. Compatible with configuration
  Disadvantages:
  1. Can only work with Apache
  2. Increases the memory overhead of Apache subprocess
  3. After changing the php.ini file, you need to restart Apache
  FastCGI
  FastCGI is an interactive program with The common protocol interface of the Web server is a variant of the early CGI (Common Gateway Interface). Compared with CGI, FastCGI reduces the overhead of interacting with the web server, and can handle more requests at a time.
  Apache can use FastCGI as mod_fcgid. Other web servers like lighttpd, nginx, Cherokee, and even Microsoft's IIS can use FastCGI. With FastCGI, multiple versions of PHP can be set up at the same time, which can be very useful in certain situations.
  FastCGI also utilizes suexec to support different users with their own instances of PHP. This feature is especially important for improving security in shared environments. FastCGI reduces the memory overhead of the web server while ensuring performance.
  Advantages:
  1. Compatible with most web servers
  2. Less memory than mod_php
  3. More configuration items, including multiple versions of PHP and suexec
  Disadvantages
  1. Complex configuration
  2. Not well known
  PHP-FPM (FastCGI Process Manager)
  PHP -FPM is a new way for web servers to use PHP and another implementation of PHP FastCGI. PHP-FPM is very useful for web applications running on small VPS and multiple servers. At the same time, it can also be used by any Web server compatible with FastCGI.
  PHP-FPM enables administrators to gracefully stop and start PHP worker processes without losing any queries. This allows us to incrementally update the configuration and binaries without losing any queries. It also allows us to restart the process urgently in case of any accidental damage.
  Advantages:
  1. Compatible with most web servers
  2. Less memory than mod_php
  3. More configuration items, including multiple versions of PHP and suexec
  Disadvantages
  1. Complex configuration
  2. Not well known by everyone
  Supplement: Four ways for Apache to run PHP
  mod_php (DSO, Dynamic Shared Object)
  CGI
  suPHP
  FastCGI
  summary
  The content is relatively abstract, the understanding is not deep, record it for future reference~:)
 
 

573767859  | Hui Yulong 

Specialties: Internet

Recommended for you:

 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324984902&siteId=291194637