In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
How php works
First of all, let's understand what is the relationship of cgi,php-cgi,fastcgi,php-fpm, which we often hear about, to help understand how php works.
Cgi protocol
The cgi protocol is used to determine webserver (such as nginx), that is, what data is passed through the content distributor and in what format.
Php-cgi process interpreter
Php-cgi is the cgi protocol process interpreter of php. Each time you start, you need to go through the process of loading php.ini file-> initializing execution environment-> processing request-> returning content to webserver- > php-cgi process exit process.
Fastcgi protocol
The fastcgi protocol is a supplement to the efficiency improvement of the cgi protocol. It mainly optimizes the need to start a cgi interpreter process every time the request comes, eliminating the need for the cgi interpreter process to reload the php.ini file and initialize the execution environment every time the webserver request is received.
Php-fpm process Manager
Php-fpm is the implementation of fastcgi protocol, is a process manager, starts including master and worker process two parts, master process listening port, receives requests from webserver, worker process generally has multiple, each worker process has a cgi process interpreter, used to execute php code
Php startup and how it works
When phpfpm is started, the master process is started, the php.ini file is loaded, the execution environment is initialized, and multiple worker processes are started. Each time the request comes, the request is passed to the worker process for processing
Php smooth restart principle
Each time the php.ini configuration is modified and restarted, a new worker process is started to load the new configuration, while the existing processes are destroyed after the work is completed, so a smooth restart is achieved.
How nginx works
If you want to understand how nginx and php work together, you also need to understand the server section of nginx's configuration file.
Server {listen 80; # listens to port 80 and receives http requests server_name www.example.com; # generally stores the URL, indicating which project root/ home/wwwroot/zensmall/public/; # is configured to store the code's root directory address or code startup entry index index.php index.html # website default homepage # when the url of the website is requested to match the prefix of location and the longest matching string is the configuration item, check the existence of the file in order, and return the first found file location / {# try_files, and check the existence of the file in order Return the first found file # $uri represents the current address without request parameters # $query_string represents the parameter try_files $uri $uri/ / index.php?$query_string carried by the request # check the $uri file in order to see if the $uri address exists. If so, return the first file found. If none exist, initiate an internal request to access / index.php?$query_string, which will be rematched to the following location request} # when requesting the php file of the website, reverse proxy to php-fpm to process location ~. Php$ {include fastcgi_params; # introduces fastcgi's configuration file fastcgi_pass 127.0.0.1php-fpm 9000 # set the IP address and port for php fastcgi process listening fastcgi_index index.php; # set the home file fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; # set the path requested by the script file}}
The overall meaning of the above server configuration is: every time nginx listens to a url request on port 80, location matching will be performed on url. If the / rule is matched, the internal request will be redirected and the internal request of / index.php?$query_string will be initiated, while the corresponding location configuration rule will send the request to the master process listening on the php-fpm on port 9000
Summary
Here is a summary of the simplest user request process:
User accesses domain name-> domain name performs DNS resolution-> request to corresponding IP server and port-> request that nginx listens to corresponding port-> nginx performs location matching on url-> executes rules under matching location-> nginx forwards request to php- > php-fpm master process listens to nginx request-> master process assigns request to one of idle worker processes-> worker process execution request-> worker process returns execution result to nginx- > nginx returns result to user
The above is the whole content of this article, I hope it will be helpful to your study, and I also hope that you will support it.
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.