This article explains in detail the principles of PHP multi-person development and what needs to be paid attention to. Let’s refer to it and learn together.
As the best language in the world, it occupies about 80% of the web. Small and medium-sized companies basically use the lnmp architecture. When there are more than 1 or 20 developers in a warehouse, each person may develop different modules and functions, and use code version control tools such as git to open different branches. The process is probably to first set up a complete environment locally and develop it. Deploy in the test environment. After self-test or tester testing, deploy in the pre-release environment. The pre-release is basically the same as the online environment, and then the product is accepted. After the acceptance is completed, it is released online.
Because it is developed in parallel, there must be situations where several functions are accepted or tested at the same time. At this time, whose code is deployed in the pre-release environment? If you switch to A's branch, B will not be able to accept it. Therefore, we hope that there will be a multi-person development environment where everyone's development process does not affect each other.
PHP operating principle
First of all, let’s analyze the operating principle of PHP and look at the language characteristics of PHP. When we initiate a request from the browser, our web server (Nginx, Apache, etc.) listens to port 80 or 443. Let's look at the simplest Nginx vhost configuration:
server { listen 80; server_name test.com; root /data/gateway/html; index index.php; location ~ \.php$ { fastcgi_pass 127.0.0.1:9001; #unix:/Users/run/php-fcgi.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } }
Nginx listens to port 80 and uses the corresponding vhost configuration when it matches that the domain name visited by the user is test.com. PHP-FPM starts a service in the server and listens to a port (such as 9001) or a unix socket. Nginx passes the request to PHP-FPM to parse the PHP code through fastcgi_pass configuration. The PHP parser starts parsing from index.php every time. , process it all the way, perform a series of logical processing, query the database or cache and other operations, and return an HTML or other results to Nginx, and Nginx returns it to the browser. The process is as follows:
CGI: It is a protocol for data exchange between Nginx and PHP_FPM.
FastCGI: Same as CGI, it is a communication protocol, but it has some optimizations in efficiency than CGI.
PHP-CGI: It is PHP’s interface program for the CGI protocol provided by Nginx.
PHP-FPM: It is PHP's interface program for the FastCGI protocol provided by Nginx. It also provides relatively intelligent task management.
Multi-person development environment
We can see from the PHP principle that PHP is actually just an interpreted script Language, each request must be parsed from index.php, then can we name many folders on the server according to the names of different developers, and in each folder, clone the code repository and switch to its own branch? . Then let Nginx handle the index in each person's directory. For example, directly access http://wulv.test.com/, obtain wulv in Nginx, and set root to the wulv directory, so that you can access the code in the wulv directory. You can set Nginx like this:
set $who www; if ($http_who != "") { set $who $http_who; } root /data/gateway/$who/html;
We can let the URL carry the user's directory, intercept it in Nginx, and carry it in the following places:
host: http://wulv.test.com
path: http://www.test.com/wulv
query: http: //www.test.com?http_who=wulv
This can generally achieve the requirements, but there are still some problems. For example, some links on the page are hard-coded and do not use relative paths. Once you Clicking it will go to www.test.com again, or some third-party applications such as OAuth need to verify the domain name. If the domain name is inconsistent with the online domain name, you cannot log in at all. So other ways are needed to achieve it, such as:
http request header
cookie
We can use the Modify Headers browser plug-in to modify the http request For header information, set a parameter http_who to wulv, and then obtain it in Nginx.
Expansion
If conditions permit, you can actually make a gateway server and create a configuration page in the configuration page Configure the directory you need to access. Next time you visit, the gateway will directly help you set the http header and proxy it to the corresponding server. In this way, you don’t even need to install browser plug-ins, which is more friendly to operations and product design.
The above is the entire content of this article. I hope it will be helpful to everyone's study. For more related content, please pay attention to the PHP Chinese website!
Related recommendations:
About php
Encryption issues during development
About PHP encryption and decryption analysis
The above is the detailed content of About the principles of multiplayer module development in PHP. For more information, please follow other related articles on the PHP Chinese website!