[PHP professional vocabulary + Concepts]

Source: Internet
Author: User
Tags php cli sapi
[Some professional PHP vocabulary + concepts] weak PHP language, case sensitive, scripting language (explanatory, text file execution), server.

OOP [Object Oriented Programming]

SAPI [Server Application Programming Interface]

Link

The programming port of the server application. It is the interface for PHP to interact with other applications. There are many ways to execute PHP scripts, either through the Web server or directly under the command line, or embedded in other programs.
SAPI provides an interface for external communication. common SAPI include cgi, fast-cgi, cli, isapi, and DLL of the apache module.

CGI
CGI is a Common Gateway Interface. it is a program. Generally speaking, CGI is like a bridge that connects the webpage to the execution program on the WEB server, it passes the commands received by HTML to the execution program on the server, and then returns the results of the execution program on the server to the HTML page. CGI provides excellent cross-platform performance and can be implemented on almost any operating system.
In CGI mode, a connection request (User request) must first create a cgi sub-process, activate a CGI process, process the request, and end the sub-process after processing. This is the fork-and-execute mode. As a result, the number of connection requests to servers in the cgi mode is limited to the number of cgi sub-processes. repeated loading of sub-processes is the main cause of low cgi performance. When the number of user requests is very large, a large amount of system resources such as internal storage and CPU time will be squeezed out, resulting in low efficiency.

FastCGI
Fast-cgi is an upgraded version of cgi. FastCGI is like a long-live CGI. it can be executed all the time, it does not take time to fork once every time. PHP uses PHP-FPM (FastCGI Process Manager), the full name of PHP FastCGI Process Manager for management.

FastCGI working principle


  1. Load FastCGI Process Manager (iis isapi or Apache Module) when the Web Server starts)

  2. FastCGI Process Manager initializes itself, starts multiple CGI interpreter processes (multiple php-cgi are visible), 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. The Web server sends CGI environment variables and standard input to the FastCGI sub-process php-cgi.

  4. After the FastCGI sub-process completes processing, the standard output and error messages are returned from the same connection to the Web Server. When the FastCGI sub-process closes the connection, the request processing is complete. The FastCGI sub-process then waits for and processes the next connection from the FastCGI Process Manager (running on the Web Server. In CGI mode, php-cgi exits here.


In the above cases, you can imagine how slow CGI is. For each Web request, PHP must re-parse php. ini, re-load all extensions, and initialize all data structures. With FastCGI, all of these occur only once when the process starts. An additional benefit is that Persistent database connection can work.

APACHE2HANDLER
PHP is used as the Apache Module. after the Apache server is started, multiple process replicas are generated in advance and reside in the memory. once you find them, use these idle sub-processes for processing, in this way, there is no latency caused by the generation of sub-processes. These server copies do not exit immediately after an HTTP request is processed, but are stuck in the computer waiting for the next request. The response to client browser requests is faster and the performance is high.
Apache module DLL:
This running mode is often used by apache servers in windows. in modularization (DLL), PHP is started and run together with the Web server. (It is an extension of apache based on CGI to speed up the running efficiency of PHP)

ISAPI:
ISAPI is Internet Server Application Program Interface. it is a set of API interfaces for Internet services provided by Microsoft. an isapi dll can be stored in the memory after being activated by a user request, waiting for another user request. you can also set multiple user request processing functions in a DLL. In addition, the isapi dll application is in the same process as the WWW server, and the efficiency is significantly higher than that of CGI.

Cli:[Php CLI mode introduction]
Cli is the command line running mode of php. it is often used, but it may not be noticed (for example: in linux, we often use "php-m" to find out which extensions are installed in PHP command line running 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.