This article gives you a detailed explanation of the PHP multi-person development principle and the need to pay attention to the place, together with reference to learn it.
As the world's most "good" language, the Web occupies about 80% of the share, small and medium-sized companies basically say LNMP architecture. When a warehouse developer is more than 1, 20 people, each person may develop different modules and functions, with the code version control tools such as git to open different branches, the process is probably first in the local set up a complete environment, the deployment in the test environment, self-test or testers tested well after deployment in the pre-release environment, Pre-release basic and online environment, and then to the product acceptance, acceptance is completed before release on line.
Because it is parallel development, there must be several functions at the same time to accept or test the situation, this time the pre-deployment environment to deploy whose code it? Switch to the branch of a, B will not be accepted. So I hope there is a multi-person development environment, everyone's development process does not affect each other.
PHP Operating principle
First, we analyze the operation principle of PHP, and look at the language features of PHP. When we launched a request from the browser, our web server (Nginx, Apache, etc.) monitored 80 or 443 ports, we look at the simplest Nginx vhost configuration:
server {listen ; 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 on port 80 when matching to user access domain name is test.com after using the corresponding Vhost configuration. PHP-FPM a service in the server, listening to a port (such as 9001) or a UNIX Socket,nginx through Fastcgi_pass configuration, passing the request to PHP-FPM to parse the PHP code, PHP parser every time from index.php to parse, go all the way, do a series of logic processing, query database or cache operation, return an HTML or other results to nginx,nginx back to the browser. Processes such as:
CGI: A protocol for data exchange between Nginx and PHP_FPM.
FastCGI: The same as CGI, is a communication protocol, but it is more efficient than CGI to do some optimization.
PHP-CGI: PHP is the interface program provided by the CGI protocol to Nginx.
PHP-FPM: PHP is the interface program provided by the FastCGI protocol to Nginx, and additionally provides some task management with relative intelligence.
Multi-person development environment
From the PHP principle we can see, PHP is actually just an explanation of the scripting language, each request to parse from index.php once, then we can not be in the server according to the name of different developers, name a lot of folders, in their respective folders, Clone good code warehouse, Switch to your own branch. Let Nginx handle the index on everyone's directory. For example, the direct access to http://wulv.test.com/, in Nginx get to WULV, the root set to wulv this directory, so that the WULV directory to access the code. You can let Nginx set this up:
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, in the Nginx interception, can be carried in a few places:
Host:http://wulv.test.com
Path:http://www.test.com/wulv
Query:http://www.test.com?http_who=wulv
In general can achieve the requirements, but still a bit of a problem, such as some links on the page is written dead, no relative path, you click on the run www.test.com, or some third-party applications such as OAuth need to verify the domain name, you and the online domain name inconsistency can not login. So it needs to be implemented in other ways, such as:
HTTP request Header
Cookies
We can use modify headers this browser plugin, modify the HTTP request header information, set a parameter http_who to WULV, and then get it in Nginx.
Expand
If there are conditions, you can actually do a gateway server, do a configuration page, configure the configuration page to access the directory, the next visit, the gateway directly to help you set the HTTP header, proxy to the corresponding server. This makes the browser plug-in unnecessary, and more friendly to the operation and product design.
The above is the whole content of this article, I hope that everyone's learning has helped, more relevant content please pay attention to topic.alibabacloud.com!