Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Introduction and function of PHP-FPM process

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces "introduction and function of PHP-FPM process". In daily operation, I believe many people have doubts about the introduction and function of PHP-FPM process. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful for you to answer the doubts about "introduction and function of PHP-FPM process"! Next, please follow the editor to study!

Introduction to PHP-FPM

PHP-FPM, the FastCGI manager of PHP, is used to replace most of the additional features of PHP FastCGI and has become standard with PHP after PHP5.3.3.

A little friend wants to ask, what the devil is FastCGI? The CGI program, also known as the Universal Gateway Interface, is an interface that allows the Web server to interact with your application. Just like the fastcgi_pass that needs to be configured in nginx, we usually use 127.0.0.1 unix:/tmp/php-cgi.sock 9000 or unix:/tmp/php-cgi.sock to configure this parameter. It means to tell nginx that incoming requests are processed using listeners on the tcp:9000 port or using unix/socket. They all point to the PHP runtime program.

To put it more colloquially, we run the php script with

Php aaa.php

Php-fpm is the equivalent of this php command. Nginx runs index.php under php $nginx_root (root configuration of the Web site root in the nginx configuration file) through fastcgi_pass. So, if you are using python or any other language, you can use their cgi program to make nginx call.

What's the difference between FastCGI and CGI? FastCGI starts a socket interface, and the server application does not need to run php on its own, just submit a request to the socket interface.

Php-fpm needs to add-- enable-fpm when compiling php. Some general integrated installation packages such as lnmp, phpStudy, etc., compile and use php-fpm by default, which is standard after all.

Tcp socket and unix socket

As mentioned above, nginx can use 127.0.0.1 php-fpm 9000 and unix:/tmp/php-cgi.sock to call php-fpm. What's the difference between them?

The former, usually with a 9000 port number, is a call in the form of tcp. That is, php-fpm starts a listening process to listen on port 9000. It will call up a tcp/ip service, and nginx will go through a tcp request process, that is, 3 handshakes and 4 waves, to the fourth transport layer of the seven layers of the network. Relatively speaking, the performance of this method will be slightly worse. After starting php-fpm, using nestat to check the port will show the occupation of port 9000.

The latter, which uses the unix socket socket service, exchanges information through sock files, and performs better because it does not have a tcp connection process and does not occupy port 9000.

For websites with high load and high traffic, unix is still recommended. For ordinary small websites, it doesn't matter which one can be used. Tcp is easier to configure and understand, and it is also the default monitoring method in php-fpm.conf.

The listen attribute in php-fpm.conf configuration is used to configure listening. The configuration here should be the same as that in nginx. If you use tcp, you will listen for 127.0.0.1 nginx 9000, and if you use unix, you will set it to / tmp/php-cgi-56.sock.

The function of PHP-FPM

The following is excerpted from the official document:

Advanced process management features that support smooth stop / start

Can work in different uid/gid/chroot environments and listen to different ports and use different php.ini profiles (instead of safe_mode settings)

Stdout and stderr logging

Be able to restart and cache the corrupted opcode in the event of an accident

Optimization support for file upload

"slow log"-recording the unusually slow running of scripts (recording not only file names, but also PHP backtrace information, which can be read and analyzed by using ptrace or similar tools for running remote processes)

Fastcgi_finish_request ()-Special function: used to continue time-consuming work in the background (input video conversion, statistical processing, etc.) after the request is completed and refreshed.

Dynamic / static subprocess generation

Basic SAPI running status information (Apache-like mod_status)

Php.ini-based configuration file

At this point, the study of "introduction and function of PHP-FPM process" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report