


[Transfer] Figure out the relationship between FastCgi and PHP-fpm, fastcgiphp-fpm_PHP tutorial
[Transfer] Find out the relationship between FastCgi and PHP-fpm, fastcgiphp-fpm
Question: Some people on the Internet say that fastcgi is a protocol , php-fpm implements this protocol; Some say that php-fpm is the manager of the fastcgi process, used to manage the fastcgi process; Some say that php-fpm is a patch of the PHP kernel; Some say that it has been modified After configuring the php.ini file, there is no way to restart smoothly, so php-fpm was born; others say that PHP-CGI is PHP’s own FastCGI manager
First of all, what is CGI? CGI is to ensure that the data passed by the web server is in a standard format, which is convenient for writers of CGI programs.
The web server (such as nginx) is just a distributor of content. For example, if /index.html
is requested, the web server will find the file in the file system and send it to the browser. What is distributed here is static data. Okay, if the request now is /index.php
, according to the configuration file, nginx knows that this is not a static file and needs to be processed by the PHP parser, then it will simply process the request and hand it over to the PHP parser. What data will Nginx pass to the PHP parser? The URL must be present, the query string must be present, the POST data must be present, and the HTTP header must be present. Well, CGI is the protocol that stipulates what data is to be transmitted and in what format to be passed to the backend for processing the request. Think carefully about where the users you use in your PHP code come from.
When the web server receives the /index.php
request, it will start the corresponding CGI program, which is the PHP parser. Next, the PHP parser will parse the php.ini file, initialize the execution environment, process the request, return the processed result in the format specified by CGI, and exit the process. The web server then returns the results to the browser.
Well, CGI is a protocol and has nothing to do with processes or anything like that. So what is fastcgi? Fastcgi is used to improve the performance of CGI programs.
Improve performance, so what are the performance problems of CGI programs? "The PHP parser will parse the php.ini file and initialize the execution environment", that's it. Standard CGI will perform these steps for each request (don't be tired! Starting the process is very tiring!), so the time to process each time will be relatively long. This is obviously unreasonable! So how does Fastcgi do it? First, Fastcgi will start a master, parse the configuration file, initialize the execution environment, and then start multiple workers. When a request comes in, the master will pass it to a worker, and then the next request can be accepted immediately. This avoids duplication of work and is naturally highly efficient. And when there are not enough workers, the master can pre-start several workers according to the configuration and wait; of course, when there are too many idle workers, some will be stopped, which improves performance and saves resources. This is fastcgi's process management.
So what is PHP-FPM? It is a program that implements Fastcgi and was officially accepted by PHP.
As we all know, the interpreter of PHP is php-cgi. php-cgi is just a CGI program. It can only parse requests and return results, but does not know how to manage processes (Your Majesty, I really can’t do that!) So there are some programs that can schedule php-cgi processes. For example, spawn-fcgi is separated from lighthttpd. Well, PHP-FPM is also like this. After a long period of development, it has gradually been recognized by everyone (you know, in the past few years, everyone complained about the poor stability of PHP-FPM), and it has become more and more popular.
Okay, let’s finally come back to your question.
1. Some people on the Internet say that fastcgi is a protocol, and php-fpm implements this protocol
Yes.
2. Some say that php-fpm is the manager of fastcgi process, which is used to manage fastcgi process
Yes. The management object of php-fpm is php-cgi. But it cannot be said that php-fpm is the manager of the fastcgi process, because as mentioned earlier, fastcgi is a protocol, and it seems that no such process exists. Even if php-fpm exists, it cannot manage it (at least for now). Some people say that php-fpm is a patch of the PHP kernel. This was true before. Because php-fpm was not included in the PHP kernel at the beginning, to use this function, you need to find php-fpm that is the same as the source code version, patch the kernel, and then compile it. Later, it became much more convenient after the PHP kernel integrated PHP-FPM. Just use the --enalbe-fpm
compilation parameter.
3. Some people say that after modifying the php.ini configuration file, there is no way to restart smoothly, so php-fpm was born
Yes, after modifying php.ini, the php-cgi process cannot be restarted smoothly. The processing mechanism of php-fpm is that new workers use new configurations, and existing workers can rest after finishing the work at hand. This mechanism is used to smooth the transition.
4. Others say that PHP-CGI is the FastCGI manager that comes with PHP. If so, why create php-fpm?
No. php-cgi is just a program that interprets PHP scripts.
Original text excerpted from: https://segmentfault.com/q/1010000000256516

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

To solve the problem of lack of PHP-FPM in Ubuntu, specific code examples are required. In the Ubuntu system, installing and configuring PHP-FPM is a common operation, but sometimes the problem of missing PHP-FPM occurs during the installation process. This article details how to solve this problem and provides specific code examples to help you complete the installation and configuration. 1. Check whether PHP-FPM has been installed. First, use the following command to check whether PHP-FPM has been installed in the system: dpkg-l|gr

Methods to solve the problem of PHP7-FPM startup failure in Linux environment. When using Linux server to build a website or application, PHP7-FPM is a commonly used PHPFastCGI process manager. However, sometimes you encounter the problem that PHP7-FPM fails to start, which may cause the website to be unable to be accessed normally. In this article, we'll cover some common workarounds and provide specific code examples. I hope this information can help you quickly solve the problem of PHP7-FPM startup failure. examine

PHP7-FPM under Linux is a common PHPFastCGI process manager, which is usually used to handle the running of PHP programs. However, sometimes during the configuration or deployment process, you may encounter a situation where PHP7-FPM fails to start, causing the website to be unable to be accessed normally. In this case, we need to take some measures to deal with and solve the problem. 1. Check the error log. First check the error log of PHP7-FPM. Usually the error log is located at /var/log/php7-fpm.

Graceful restart GR is the abbreviation of Graceful Restart. It is a mechanism to ensure that forwarding services are not interrupted when the protocol is restarted. The core of the GR mechanism is that when a device restarts the protocol, it can notify its surrounding devices to maintain stable neighbor relationships and routes to the device within a certain period of time. After the protocol is restarted, peripheral devices assist it in synchronizing information (including various topology, routing and session information maintained by routing/MPLS-related protocols that support GR), so that the device can be restored to the state before the restart in the shortest possible time. state. There will be no route flapping during the entire protocol restart process, and there will be no change in the packet forwarding path. The entire system can forward data without interruption. This process is called a smooth restart.

For one of our web projects, due to the increase in new cities, the number of visits has increased and the pressure on the db has increased. As a business party that provides interfaces, a large number of "502" requests have been reported recently by downstream feedback. 502, badgateway, is usually an error in upstream (here is PHP). For PHP, the common cause of 502 is that the script execution exceeds the timeout setting time, or the timeout setting is too large, resulting in the PHP process not being released for a long time, and there are no idle workers. process to pick up guests. Our project is caused by the PHP execution time setting being too short. In this case, you can first increase the PHP execution time appropriately and ensure that 502 is cleared first. Optimization will cost more after all.

When solving the challenge of missing PHP-FPM in your Ubuntu system, you need to follow a series of steps to install and configure PHP-FPM. PHP-FPM (FastCGIProcessManager) is a process manager that handles dynamic page requests and can improve the performance and stability of PHP applications. The following details how to install and configure PHP-FPM on an Ubuntu system, with specific code examples to help solve this challenge. Step 1: Updating the system is in progress

nginx is different from apache. In apache, you can directly specify the error log of php, so that the error information during php execution is directly input into the error log of php, which can be easily queried. In nginx, things become like this: nginx only records access logs for page visits. There will be no php errorlog information. nginx sends the request for php to the php-fpmfastcgi process for processing. The default php-fpm will only output the error message of php-fpm, and the error log of php cannot be seen in the errorslog of php-fpm. The reason is that the configuration file php of php-fpm

It is common practice to use PHP7-FPM as the server-side script running environment on Linux servers, but sometimes you may encounter startup exceptions. This article will introduce some techniques for dealing with PHP7-FPM startup exceptions, and provide some specific code examples to help readers better solve the problem. 1. Check the configuration file. The configuration file of PHP7-FPM is usually located in the /etc/php/7.x/fpm/pool.d/ directory to ensure that the configurations in the configuration file are correct. Can make
