Three ways to run PHP under Linux

  
 

Under linux, php has three modes of operation: 1. APACHE2HANDLERPHP
As an Apache module, after the system is started, the Apache server pre-generates multiple copies of the process to reside in memory, once a request appears. , immediately use these spare child processes for processing, so there is no delay caused by the child process. These server copies do not exit immediately after processing an HTTP request, but stay in the computer for the next request. Requests for client browsers are faster and perform better.

2. The CGIcgi method encounters a connection request to create a cgi child process, then processes the request, and ends the child process after processing. This is the fork-and-execute mode. So how many cgi subprocesses there are in the cgi way server? Sub-process repeated loading is the main reason for the low performance of cgi.

3. CGI-FCGIFastCGI is like a long-live CGI that can be executed all the time. Once activated, it won't take time to fork once. PHP uses PHP-FPM (FastCGI Process Manager), fully called PHP FastCGI Process Manager for management.

How FastCGI works 1. Load the FastCGI Process Manager (IIS ISAPI or Apache Module) when Web Server starts. 2. The FastCGI Process Manager initializes itself and starts multiple CGI interpreter processes. -cgi) and wait for a connection from the Web Server. 3. When the client requests to reach the Web Server, the FastCGI Process Manager selects and connects to a CGI interpreter. The web server sends the CGI environment variables and standard input to the FastCGI child process php-cgi. 4. After the FastCGI child process finishes processing, return the standard output and error information from the same connection to the Web Server. When the FastCGI child process closes the connection, the request is processed. The FastCGI child process then waits and processes the next connection from the FastCGI Process Manager (running in the Web Server). In CGI mode, php-cgi quits here.

In the above situation, you can imagine how slow CGI is usually. Every web request PHP must reparse php.ini, reload all extensions, and reinitialize all data structures. With FastCGI, all of this happens only once when the process starts. An added bonus is that the Persistent database connection works.

Copyright © Windows knowledge All Rights Reserved