PHP run mode

Source: Internet
Author: User

The five most common modes of operation are: CGI ,fast-cgi,CLI,ISAPI, Apache of the die block DLL , the following author of the five operating modes to do some of their own analysis, there is a wrong place, please leave a message.

CGI Run mode

CGI is a Universal Gateway Interface (Common gateway Interface), which is a program that is popular for CGI , like a bridge, that pages and The execution program in the WEB server is connected, it passes the instruction that the HTML receives to the server execution program, and then returns the result of the server execution program to the HTML page. CGI has excellent cross-platform performance and can be implemented on almost any operating system.

The CGI method encounters a connection request (user request) to create a CGI subprocess, activate a CGI process, then process the request, and end the subprocess after processing. This is the fork-and-execute mode. So How many CGI sub-processes are there for the CGI server , and the sub-process loading is the main reason for the poor CGI performance. will be when the user requests a very long time, will be a lot of crowding out the system resources such as memory,CPU times, resulting in low performance.

FAST-CGI operating mode

fast-cgi is an upgraded versionof CGI ,FastCGI like a resident (long-live) type CGI , it can be executed all the time, so long as it is activated, it does not have to spend every Fork one time. php uses php-fpm (FastCGI Process Manager), full name php FastCGI managed by the process manager.

How the FastCGI works

1.when Web Server starts, load the FastCGI process Manager (IIS ISAPI or Apache Module)

2.theFastCGI process Manager itself Initializes a number of CGI interpreter processes ( more than one can be seen php-cgi) and wait for a connection from the Web Server .

3. When a client request arrives at Web Server , theFastCGI process Manager selects and connects to a CGI interpreter. Web Server sends CGI environment variables and standard input to the FastCGI child process php-cgi.

4,FastCGIreturns standard output and error information from the same connection after the child process finishes processingWeb Server. WhenFastCGIwhen the child process closes the connection, the request is processed to completion. FastCGIThe child process then waits and processes theFastCGIProcess Manager(run onWeb Serverin)the next connection. In theCGImode,php-cgiAnd then we quit.

In the above scenario, you can imagine How slow CGI is usually. Every Web request PHP must re-parse php.ini, reload all extensions, and initialize all data structures. With FastCGI, all of this occurs only once when the process is started. An additional benefit is that the persistent database connection (persistent connection) can work.

CLI Run mode

The CLI is the command-line run mode of PHP, which is often used by people, but may not be noticed (for example: we often use "php-m" under Linux ). "Find PHP installed those extensions is the php command line running mode; interested students can enter php-h to delve into the operating mode)

ISAPI Run mode

IsapithatInternet Server application program Interfaceis a set of Microsoft-orientedInternetService ofAPIinterface, aISAPIof theDLL, can be long in memory after being activated by a user request, waiting for another request of the user, can also be in aDLLmultiple user Request handler functions, in addition,ISAPIof theDLLApplications andWWWservers are in the same process and are significantly more efficient thanCGI. (due to the exclusivity of Microsoft, it can only run onWindowsEnvironment)

Apache2handler

PHP as an Apache module,theApache Server after the system startup, pre-generated multiple copies of the process resides in memory, once a request appears, Immediately use these spare child processes for processing, so there is no delay caused by the generation of child processes. These server replicas do not exit immediately after processing an HTTP request, but instead stay on the computer waiting for the next request. Requests for customer browsers respond faster and have higher performance.

the DLL run mode of Apache module

This mode of operation is often used in Windows environments where we use Apache servers, and in a modular (DLL) format , PHP is started and run with the WEB server. (It is an extension of Apache based on CGI, which accelerates The efficiency of PHP operation)

For each of the above operating mode has its own advantages and disadvantages, there is no absolute good and bad, mainly to see what the environment under what kind of needs.

PHP run mode

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.