PHP----SAPI

Source: Internet
Author: User
Tags php cli sapi

Sapi:server application Programming Interface Server-side application programming port. It is the interface between PHP and other applications, and PHP scripts can be executed in a number of ways, either through a Web server or directly under the command line or embedded in other programs.
SAPI provides an interface to external communication, common SAPI are: CGI, fast-cgi, CLI, ISAPI, Apache module DLL

Cgi
CGI is the Universal Gateway Interface (Common Gateway Interface), it is a program, the popular CGI is like a bridge, the Web page and the Web server to connect the execution program, it takes HTML received instructions to the server's execution program, The results of the server execution program are then returned 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.

FastCGI
FAST-CGI is an upgraded version of CGI, fastcgi is like a resident (long-live) CGI, which can be executed all the time, so long as it is activated, it does not have to take a moment to fork it every time. PHP uses PHP-FPM (FastCGI process Manager), the full name of the PHP FastCGI process Manager to manage.

How the FastCGI works

    1. Load fastcgi Process Manager (IIS ISAPI or Apache Module) when Web server starts
    2. The FASTCGI process Manager itself initializes, starts multiple CGI interpreter processes (visible multiple php-cgi) and waits for a connection from the Web server.
    3. When a client request arrives at the Web server, the FASTCGI 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. The FASTCGI child process returns standard output and error information from the same connection to the Web Server after processing is complete. When the fastcgi child process closes the connection, the request is processed to completion. The fastcgi child process then waits and processes the next connection from the FASTCGI process Manager (running in Web server). In CGI mode, php-cgi exits here.

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.

Apache2handler
PHP as an Apache module, the Apache 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 to process, so there is no generation of child process caused by the delay. 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 Apache module DLL:
This is a running mode that we used to use with Apache servers in a Windows environment, and in a modular (DLL), PHP is started and run with a Web server. (It is an extension of Apache based on CGI, which accelerates the efficiency of PHP operation)

Isapi:
ISAPI is the Internet Server application program Interface, is a set of Internet service-oriented API interfaces provided by Microsoft. An ISAPI DLL can be in memory after being requested by the user, waiting for another request of the user, and can set up multiple user request handlers in a DLL, in addition, the ISAPI DLL application and the WWW server are in the same process. is significantly more efficient than CGI.

CLI: [Introduction to PHP CLI 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" in Linux to find PHP installed those extensions are PHP command line run mode.)

PHP----SAPI

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.