Home  >  Article  >  Detailed explanation of the principles of PHP multiplayer development environment

Detailed explanation of the principles of PHP multiplayer development environment

小云云
小云云Original
2017-12-08 09:12:162683browse

As a PHP developer, sometimes we cannot complete a project or a function alone, just like when a warehouse developer has more than 1 or 20 people, each person may develop different modules and functions, using code versions Control tools such as git open different branches. The process is probably to first set up a complete environment locally, develop it and deploy it in the test environment. After self-test or tester testing, deploy it in the pre-release environment. The release is basically the same as the online environment, and then the product is inspected. After the acceptance is completed, the product is released online. Since 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. In this article, we will share with you an analysis of the principles of the PHP multiplayer development environment.

PHP operating principle

First of all, let’s analyze the operating principle of PHP and take a 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's 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 domain name when the domain name visited by the user is test.com The vhost configuration. PHP-FPM starts a service in the server and listens to a port (such as 9001) or a unix socket. Nginx is configured through fastcgi_pass and passes the request to PHP-FPM To parse the PHP code, the PHP parser starts parsing from index.php each time, processes it all the way, performs a series of logical processing, queries the database or cache, etc., and returns a HTML Or other results are given to Nginx, and Nginx is returned to the browser. The process is as follows:

Detailed explanation of the principles of PHP multiplayer development environment

  • ##CGI: It is Nginx and ## A protocol for data exchange between #PHP_FPM.

  • FastCGI

    : Same as CGI, it is a communication protocol, but it is more efficient than CGI optimization.

  • PHP-CGI

    : It is the interface of PHP to the CGI protocol provided by Nginx program.

  • PHP-FPM

    : It is the interface of PHP to the FastCGI protocol provided by Nginx The program also provides some relatively intelligent task management.

  • Multi-person development environment

We can see from the

PHP

principle that PHP is actually just an interpreted scripting language. Every request To parse it once from index.php, can we name many folders on the server according to the names of different developers, and in each folder, clone Good Code Warehouse , switch to your own branch. Then let Nginx handle the index in each person's directory. For example, visit http://wulv.test.com/ directly, get wulv in Nginx, and set root to wulv This directory, in this way, you can access the code in the wulv directory. You can set Nginx like this: <pre class="brush:php;toolbar:false">set $who www; if ($http_who != &quot;&quot;) {    set $who $http_who; } root /data/gateway/$who/html;</pre> We can let

URL

carry the user's directory, and intercept it in Nginx. You can add the following Places to carry:

  • 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. If you do not use a relative path, you will go to
  • www.test.com
as soon as you click, or some third-party applications such as

OAuth need to verify the domain name, and your domain name is inconsistent with the online domain name. Can't 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
header information and set a parameter

http_who to wulv, then get it in Nginx. Expand

If conditions permit, you can actually make a gateway server and create a configuration page. Configure the directories that need to be accessed in the configuration page. Next time you visit, the gateway will directly help You set

http header

to proxy 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.

PHP 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 set up a set locally first. The complete environment is developed and deployed in the test environment. After self-test or tester testing, it is deployed 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 and launched 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 take a 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's 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 domain name when the domain name visited by the user is test.com The vhost configuration. PHP-FPM starts a service in the server and listens to a port (such as 9001) or a unix socket. Nginx is configured through fastcgi_pass and passes the request to PHP-FPM To parse the PHP code, the PHP parser starts parsing from index.php each time, processes it all the way, performs a series of logical processing, queries the database or cache, etc., and returns a HTML Or other results are given to Nginx, and Nginx is returned to the browser. The process is as follows:

Detailed explanation of the principles of PHP multiplayer development environment

  • ##CGI: It is Nginx and ## A protocol for data exchange between #PHP_FPM.

  • FastCGI

    : Same as CGI, it is a communication protocol, but it is more efficient than CGI optimization.

  • PHP-CGI

    : It is the interface of PHP to the CGI protocol provided by Nginx program.

  • PHP-FPM

    : It is the interface of PHP to the FastCGI protocol provided by Nginx The program also provides some relatively intelligent task management.

  • Multi-person development environment

We can see from the

PHP

principle that PHP is actually just an interpreted scripting language. Every request To parse it once from index.php, can we name many folders on the server according to the names of different developers, and in each folder, clone Good Code Warehouse , switch to your own branch. Then let Nginx handle the index in each person's directory. For example, visit http://wulv.test.com/ directly, get wulv in Nginx, and set root to wulv This directory, in this way, you can access the code in the wulv directory. You can set Nginx like this: <pre class="brush:php;toolbar:false">set $who www; if ($http_who != &quot;&quot;) {    set $who $http_who; } root /data/gateway/$who/html;</pre> We can let

URL

carry the user's directory, and intercept it in Nginx. You can add the following Places to carry:

  • 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. If you do not use a relative path, you will go to
  • www.test.com
as soon as you click, or some third-party applications such as

OAuth need to verify the domain name, and your domain name is inconsistent with the online domain name. Can't 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
header information and set a parameter

http_who to wulv, then get it in Nginx. Expand

If conditions permit, you can actually make a gateway server and create a configuration page. Configure the directories that need to be accessed in the configuration page. Next time you visit, the gateway will directly help You set

http header

to proxy 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.

Related recommendations:

php Chinese website acquires the secret of phpstudy integrated development environment with the largest number of users in the country

php Integrated Development Environment Encyclopedia

How to build a JSP development environment


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn