Principle analysis of PHP multiplayer module development
This article explains in detail the principles of PHP multi-person development and what needs to be paid attention to. Let’s refer to it and learn together.
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 first set up a complete environment locally and develop it. Deploy in the test environment. After self-test or tester testing, deploy 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 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 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 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 it matches that the domain name visited by the user is test.com. PHP-FPM starts a service in the server and listens to a port (such as 9001) or a unix socket. Nginx passes the request to PHP-FPM to parse the PHP code through fastcgi_pass configuration. The PHP parser starts parsing from index.php every time. , process it all the way, perform a series of logical processing, query the database or cache and other operations, and return an HTML or other results to Nginx, and Nginx returns it to the browser. The process is as follows:
CGI: It is a protocol for data exchange between Nginx and PHP_FPM.
FastCGI: Same as CGI, it is a communication protocol, but it has some optimizations in efficiency than CGI.
PHP-CGI: It is PHP’s interface program for the CGI protocol provided by Nginx.
PHP-FPM: It is PHP's interface program for the FastCGI protocol provided by Nginx. It also provides relatively intelligent task management.
Multi-person development environment
We can see from the PHP principle that PHP is actually just an interpreted script Language, each request must be parsed from index.php, then can we name many folders on the server according to the names of different developers, and in each folder, clone the code repository and switch to its own branch? . Then let Nginx handle the index in each person's directory. For example, directly access http://wulv.test.com/, obtain wulv in Nginx, and set root to the wulv directory, so that you can access the code in the wulv directory. You can set Nginx like this:
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, intercept it in Nginx, and carry it in the following places:
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 and do not use relative paths. Once you Clicking it will go to www.test.com again, or some third-party applications such as OAuth need to verify the domain name. If the domain name is inconsistent with the online domain name, you cannot 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 For header information, set a parameter http_who to wulv, and then obtain it in Nginx.
Expansion
If conditions permit, you can actually make a gateway server and create a configuration page in the configuration page Configure the directory you need to access. Next time you visit, the gateway will directly help you set the http header and proxy it 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.
Explanation on using XHProf to find PHP performance bottlenecks
##Related summary of custom template instructions in the Laravel framework
An example of how to implement quick sort recursively in PHP
The above is the detailed content of Principle analysis of PHP multiplayer module development. For more information, please follow other related articles on the PHP Chinese website!

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

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

This tutorial demonstrates how to efficiently process XML documents using PHP. XML (eXtensible Markup Language) is a versatile text-based markup language designed for both human readability and machine parsing. It's commonly used for data storage an

If you are an experienced PHP developer, you might have the feeling that you’ve been there and done that already.You have developed a significant number of applications, debugged millions of lines of code, and tweaked a bunch of scripts to achieve op

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

A string is a sequence of characters, including letters, numbers, and symbols. This tutorial will learn how to calculate the number of vowels in a given string in PHP using different methods. The vowels in English are a, e, i, o, u, and they can be uppercase or lowercase. What is a vowel? Vowels are alphabetic characters that represent a specific pronunciation. There are five vowels in English, including uppercase and lowercase: a, e, i, o, u Example 1 Input: String = "Tutorialspoint" Output: 6 explain The vowels in the string "Tutorialspoint" are u, o, i, a, o, i. There are 6 yuan in total

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

What are the magic methods of PHP? PHP's magic methods include: 1.\_\_construct, used to initialize objects; 2.\_\_destruct, used to clean up resources; 3.\_\_call, handle non-existent method calls; 4.\_\_get, implement dynamic attribute access; 5.\_\_set, implement dynamic attribute settings. These methods are automatically called in certain situations, improving code flexibility and efficiency.
