How PHP works
1. The operating principle of PHP
Typical question: The operating principle of Nginx PHP - FPM
CGI: Some early Web Servers can only process simple HTML static files, but with the advancement of technology With the development, dynamic languages (such as PHP, Python) appeared. In this, if we want to process PHP, we have to hand over a PHP parser for processing, but after PHP is processed, how to communicate with our Web Server? this is a problem. In order to solve the communication between different language processors and Web Server, the CGI protocol emerged. As long as the program is written according to the CGI protocol, the communication between the language parser and the Web Server can be realized. (For example: PHP's CGI program) In this process, CGI is a protocol bridge between the PHP parser and the Web Server.
FastCGI: Although CGI solves the problem of communication between PHP and Web Server, its efficiency is very low because every time the Web Server receives a request, it will open a new CGI process, and then terminate this process when the request ends. Processes, if we have 10,000, 100,000, or 1 million such requests at this time, we will open 100,000 or 1 million new processes, and then terminate them. In itself, , a huge waste of our resources. At this time, FastCGI appeared. It mainly appeared as an improved version of CGI. After each request is processed, the process will not be terminated, but the process will be retained so that the process can handle multiple requests at one time. In this case, There is no need to reopen a process every time, which greatly improves our efficiency.
PHP-FPM: (FastCGI Process Manager: FastCGI process manager), FPM is an implementation of FastCGI and provides process management functions. The process includes two processes: master process and worker process. There is only one master process, which is responsible for listening to the port and receiving requests from the Web Server. There are generally multiple worker processes, and the specific number will be defined in the FPM configuration. Each process A PHP parser is embedded inside each process (that is where the PHP code is actually executed). In other words, the worker processes the PHP code, while the master mainly listens on the port and receives requests from the Web Server. In itself, the master listening port is 9000 by default, and the 9000 port is proxied through Nginx's reverse proxy, so here we can complete FPM related processing.
2. Briefly describe the differences between CGI, FastCGI and PHP-FPM.
CGI: In order to contact a protocol in the Web Server and the PHP parser, it acts as a bridge.
FastCGI: It is an improved version of CGI.
PHP-FPM: FastCGI Process Manager, FastCGI process manager.
The above is the detailed content of How PHP works. 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

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

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



Alipay PHP...

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,

The application of SOLID principle in PHP development includes: 1. Single responsibility principle (SRP): Each class is responsible for only one function. 2. Open and close principle (OCP): Changes are achieved through extension rather than modification. 3. Lisch's Substitution Principle (LSP): Subclasses can replace base classes without affecting program accuracy. 4. Interface isolation principle (ISP): Use fine-grained interfaces to avoid dependencies and unused methods. 5. Dependency inversion principle (DIP): High and low-level modules rely on abstraction and are implemented through dependency injection.

How to automatically set the permissions of unixsocket after the system restarts. Every time the system restarts, we need to execute the following command to modify the permissions of unixsocket: sudo...

How to debug CLI mode in PHPStorm? When developing with PHPStorm, sometimes we need to debug PHP in command line interface (CLI) mode...

Article discusses late static binding (LSB) in PHP, introduced in PHP 5.3, allowing runtime resolution of static method calls for more flexible inheritance.Main issue: LSB vs. traditional polymorphism; LSB's practical applications and potential perfo

Sending JSON data using PHP's cURL library In PHP development, it is often necessary to interact with external APIs. One of the common ways is to use cURL library to send POST�...

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.
