search
HomePHP FrameworkWorkermanworkerman's talk about several operating modes in PHP

The following column of workerman usage tutorial will introduce you to several operating modes in PHP. I hope it will be helpful to friends in need!

workerman's talk about several operating modes in PHP

We know that the workerman program needs to run in php-cli mode, which is the command line mode. We need to understand this. It is said that PHP currently has 4 operating modes, namely CGI, FastCGI, CLI and Web module mode.

CGI

The full name is "Common Gateway Interface", which allows a client to connect from a web browser to a program running on a web server. The program requests data, which describes a standard for transmitting data between the client and the program. In addition, CGI is independent of any language, so it can be written in any language, as long as the language has standard input, output and environment variables. Such as php, perl, tcl, etc.

CGI needs to open a separate sub-process for maintenance for each user request, so performance problems will occur when the number is large, and it has been rarely used in recent years.

FastCGI

An upgraded version of CGI, FastCGI is like a long-live CGI. It can be executed all the time. As long as it is activated, it will not It will take time to parse php.ini, reload all dll extensions and reinitialize all data structures every time.

PHP uses PHP-FPM (FastCGI Process Manager), the full name of which is PHP FastCGI Process Manager, for management.

FastCGI working principle

The FastCGI process manager is loaded when the Web Server starts;

The FastCGI process manager initializes itself and starts multiple CGI interpretations server process and waits for a connection from the Web Server;

When a client request arrives at the Web Server, the FastCGI process manager selects and connects to a CGI interpreter. The web server sends CGI environment variables and standard input to the FastCGI subprocess php-cgi.

After the FastCGI sub-process completes processing, it returns standard output and error information to the Web Server from the same connection. When the FastCGI child process closes the connection, the request is processed. The FastCGI child process then waits for and handles the next connection from the FastCGI process manager.

In normal CGI mode, this is the end and you have to start over again next time. But in FastCGI, all this happens only once, when the process starts. An added bonus is that persistent database connections work.

Cli

PHP-CLI is the abbreviation of PHP Command Line Interface, which is the interface for PHP to run on the command line, which is different from the PHP environment running on the Web server ( PHP-CGI, etc.).

We often use "php -m" under Linux to find out which extensions PHP has installed, which is the PHP command line running mode. You can type php -h to see what specific commands are available.

In php-cli mode we can directly start a php file and execute it, just like in workererman

php index.php start

It should be noted that there is no statement about php running timeout in php-cli mode .

Module loading

is generally for apache. In this way, their common essence is to use LoadModule to load phpX_module, which is to use php as apache. A submodule to run. When accessing a php file through the web, apache will call phpX_module to parse the php code. So how does phpX_module pass the data to the php parser to parse the php code? The answer is through sapi.

So, the above process of apache calling php is as follows:

apache -> httpd -> php5_module -> sapi -> php

Every time apache receives a request, it will generate a process to connect to php to complete the request through sapi. As you can imagine, if Once there are too many users and too many concurrent users, the server will be unable to bear it.

Moreover, when mod_php is compiled into apache, it is difficult to determine whether it is a problem with PHP or apache when a problem occurs.

Summary

If you want to build a high-performance PHP WEB server, the best way currently is Apache/Nginx FastCGI PHP-FPM (PHP-CGI) method , don’t use Module loading or CGI method anymore

The above is the detailed content of workerman's talk about several operating modes in PHP. For more information, please follow other related articles on the PHP Chinese website!

Statement
This article is reproduced at:segmentfault. If there is any infringement, please contact admin@php.cn delete

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

Video Face Swap

Video Face Swap

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

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),