Analysis of PHP multiplayer module development principles and php module principles
As the world's most "good" language, the web account for about 80% of the share, basically speaking of lnmp architecture for small and medium-sized companies. When there are more than developers in a repository, 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 build a complete environment locally, develop and deploy it in the testing environment, and deploy it in the pre-release environment after self-testing or testing by testers. The pre-release environment is the same as the online environment, then the product is accepted and released after acceptance.
Because it is a parallel development, there must be several features that can be accepted or tested at the same time. In this case, what code should I deploy in the pre-release environment? Switch to the branch of A, and B cannot accept the request. Therefore, we hope that there will be a multi-person development environment, and the development process of each person will not affect each other.
PHP running principle
First, let's analyze the operating principles of PHP and look at the Language Features of PHP. When we initiate a request from a browser, our web server (Nginx, Apache, etc.) listens to port 80 or port 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 the domain name accessed by the user is test.com. PHP-FPM a service in the server, listening to a port (such as 9001) or a unix socket, Nginx through fastcgi_pass configuration, the request is passed to the PHP-FPM to parse PHP code, the PHP parser starts from index every time. php starts parsing, processing all the way, performing a series of logical processing, querying the database or caching operations, returning an HTML or other result to Nginx, Nginx then returning to the browser. The process is as follows:
CGI: a protocol for data exchange between Nginx and PHP_FPM.
FastCGI: Same as CGI, It is a communication protocol, but it is more efficient than CGI.
PHP-CGI: Is the CGI protocol provided by PHP to Nginx interface program.
PHP-FPM: Is the PHP FastCGI protocol for Nginx interface program, also provides relatively intelligent task management.
Multi-Person Development Environment
From the principles of PHP, we can see that PHP is actually just an interpreted script language, and every request is sent from index. php resolves the issue once. Can we name many folders on the server based on the names of different developers, clone the code repository in their respective folders, and switch to their own branch. Then let Nginx process the index under each directory. For example, access http://wulv.test.com/directly, obtain wulv in Nginx, set root to the wulv directory, and then access the code under the wulv directory. Nginx can be set like this:
set $who www;if ($http_who != "") { set $who $http_who;}root /data/gateway/$who/html;
We can enable the URL to carry the user's directory. we can intercept it in Nginx and include it in the following places:
Host: http://wulv.test.com
Path: http://www.test.com/wulv
Query: http://www.test.com? Http_who = wulv
In this way, the requirements can be basically met, but there is still a problem. For example, some links on the page are written to death, and no relative path is used. You can click www.test.com again, or some third-party applications, such as OAuth, need to verify the domain name. If you are inconsistent with the online domain name, you cannot log in. Therefore, other methods are required, such:
Http request header
Cookie
We can use the Modify Headers browser plug-in to Modify the http request header information, set the http_who parameter to wulv, and obtain it in Nginx.
Expansion
If conditions are met, you can create a gateway server and configure the page to configure the directory to be accessed. The gateway will help you set the http header for the next visit, proxy to the corresponding server. In this way, you do not need to install any browser plug-ins, which is more user-friendly for operation and product design.