Table of Contents
PHP operating principle
We can see from the
http header
Home headlines Detailed explanation of the principles of PHP multiplayer development environment

Detailed explanation of the principles of PHP multiplayer development environment

Dec 08, 2017 am 09:12 AM
php principle 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;
  }
}
Copy after login
Copy after login

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: <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 != &quot;&quot;) {    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

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;
  }
}
Copy after login
Copy after login

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: <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 != &quot;&quot;) {    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

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 of this Website
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

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

CakePHP Date and Time CakePHP Date and Time Sep 10, 2024 pm 05:27 PM

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

Discuss CakePHP Discuss CakePHP Sep 10, 2024 pm 05:28 PM

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

CakePHP File upload CakePHP File upload Sep 10, 2024 pm 05:27 PM

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

CakePHP Creating Validators CakePHP Creating Validators Sep 10, 2024 pm 05:26 PM

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

CakePHP Logging CakePHP Logging Sep 10, 2024 pm 05:26 PM

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

How To Set Up Visual Studio Code (VS Code) for PHP Development How To Set Up Visual Studio Code (VS Code) for PHP Development Dec 20, 2024 am 11:31 AM

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 Quick Guide CakePHP Quick Guide Sep 10, 2024 pm 05:27 PM

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.