4 Common ways to run PHP

Source: Internet
Author: User
Tags command line data structures html page http request sapi

This article mainly introduced PHP 4 kinds of common operation way, this article explained the CGI, FastCGI, Apache2handler, CLI and so on 4 kinds of Operation Way, needs the friend may refer to under

Sapi:server application Programming Interface Service-side application programming port. He is the interface that PHP interacts with other applications, and PHP scripts can be executed in many ways, either through a Web server or directly on the command line, or embedded in other programs. SAPI provides an interface to communicate with the outside, Common SAPI include: CGI, fast-cgi, CLI, dll of Apache module and so on.

  1. CGI

CGI is the Universal Gateway Interface (Common Gatewag interface), it is a program, popular speaking CGI is like a bridge, the Web page and the Internet server to connect the Executive program, it will receive the HTML instructions to the server's execution program, Return the results 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, activates a CGI process, and then processes the request, finishes the subprocess, and ends the child process. This is the Fork-and-execute mode. So the CGI server has how many connection requests there will be the number of CGI child processes, the child process repeatedly loading is the main reason for the low performance of CGI. When the user requests a very large number of users will be heavily crowding out the system's resources such as memory, CPU time, etc., resulting in low performance.

  2, FastCGI

FAST-CGI is an upgraded version of CGI, fastcgi is like a resident (long-live) CGI, which can be executed all the time, as long as it is activated, it will not take a while to fork once. PHP uses PHP-FPM (FastCGI process Manager), the full name of the PHP FastCGI process Manager for management.

Load the FASTCGI Process Manager (IIS ISAPI or Apache Module) when the WEB server is started. FastCGI the process manager itself, initiates multiple CGI interpreter processes (visible multiple php-cgi) 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.

The fastcgi process completes processing and returns 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 process then waits and processes the next connection from the FASTCGI process Manager (running in Web server). In the CGI mode, php-cgi quits here.

In the above scenario, you can imagine how slow CGI is usually. Each Web request PHP must reparse php.ini, reload all extensions, and reinitialize all data structures. With fastcgi, all of these occur only once when the process is started. An additional benefit is that persistent database connections (persistent DB connection) can work.

  3, Apache2handler
PHP as the Apache module, the Apache server after the system is started, the advance generation of multiple copies of the process reside in memory, once the request appears, immediately use these free subprocess processing, so there is no delay in the generation of child processes. These server replicas do not exit immediately after processing an HTTP request, but stay on the computer for the next request. Faster response to client browser requests and higher performance.

  4. CLI

The CLI is PHP's command-line run mode, which is often used, but may not be noticed (for example: we often use "php-m" in Linux to find PHP installed those extensions is the PHP command line operation mode;

Related Article

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.