Detailed explanation of the principles of PHP multiplayer development environment
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:
##CGI
: It is
Nginxand ## A protocol for data exchange between #PHP_FPM
.- FastCGI
: Same as
CGI
, it is a communication protocol, but it is more efficient thanCGI
optimization. - PHP-CGI
: It is the interface of
PHP
to theCGI
protocol provided byNginx
program. - PHP-FPM
: It is the interface of
PHP
to theFastCGI
protocol provided byNginx
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: <div class="code" style="position:relative; padding:0px; margin:0px;"><div class="code" style="position:relative; padding:0px; margin:0px;"><pre class="brush:php;toolbar:false">set $who www;
if ($http_who != "") {
set $who $http_who;
}
root /data/gateway/$who/html;</pre><div class="contentsignin">Copy after login</div></div><div class="contentsignin">Copy after login</div></div>
We can let
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
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
-
We can use the Modify Headers browser plug-in to modify the http request
http_who to
wulv, then get it in
Nginx.
Expand
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:
##CGI
: It is
Nginxand ## A protocol for data exchange between #PHP_FPM
.- FastCGI
: Same as
CGI
, it is a communication protocol, but it is more efficient thanCGI
optimization. - PHP-CGI
: It is the interface of
PHP
to theCGI
protocol provided byNginx
program. - PHP-FPM
: It is the interface of
PHP
to theFastCGI
protocol provided byNginx
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: <div class="code" style="position:relative; padding:0px; margin:0px;"><div class="code" style="position:relative; padding:0px; margin:0px;"><pre class="brush:php;toolbar:false">set $who www;
if ($http_who != "") {
set $who $http_who;
}
root /data/gateway/$who/html;</pre><div class="contentsignin">Copy after login</div></div><div class="contentsignin">Copy after login</div></div>
We can let
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
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
-
We can use the Modify Headers browser plug-in to modify the http request
http_who to
wulv, then get it in
Nginx.
Expand
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

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

To work on file upload we are going to use the form helper. Here, is an example for file upload.

Validator can be created by adding the following two lines in the controller.

Logging in CakePHP is a very easy task. You just have to use one function. You can log errors, exceptions, user activities, action taken by users, for any background process like cronjob. Logging data in CakePHP is easy. The log() function is provide

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

CakePHP is an open source MVC framework. It makes developing, deploying and maintaining applications much easier. CakePHP has a number of libraries to reduce the overload of most common tasks.