PHP Kernel: SAPI Quest

Source: Internet
Author: User
Tags sapi zend

let's start with the PHP architecture diagram .

What SAPI?

SAPI's Chinese translation: Server-side application programming interface. It is responsible for PHP interaction with other applications data. Other applications here may be shell or Apache, and so on. The common SAPI are:

CGI,FAST-CGI,CLI (for the Shell), ISAPI (for IIS), Embed (for C + +), and so on.

Example: When in the shell (Command line under window) input: PHP index.php at this time, by the CLI this SAPI is responsible for the user's request processing. To define a SAPI, you need to define a struct body.

The SAPI structure of the CLI is as follows: (/PATH/TO/PHP-SRC/SAPI/CLI/PHP_CLI.C)

struct SAPI_MODULE_STRUCT defines some of the operations that are done when a CLI SAPI is started, let's take a look at the following.

1: "CLI" defines the name of the current SAPI, the Phpinfo function will use this name.

2:php_cli_startup, the complete definition of the function is

You can see that the function will call Php_module_startup. This is a PHP initialization function (see section: http://www.walu.cc/phpbook/1.3.md php life cycle)

3:php_module_shutdown_wrapper, the definition of a function is:

Just simple packing for Php_module_shutdown ()

4:php does some initialization, resource-allocation transactions for each request, where there is no corresponding handler for the CLI. But it's different for mod_php. He wants to register a resource destructor, request space, initialize environment variables, and so on in the Apache pool.

5:sapi_cli_deactivate, finishing the work.

6:sapi_cli_ub_write, provides a function handle to the Zend flush cache,

The Sapi_cli_single_write function writes data to the STDOUT

7:sapi_cli_flush,

The function calls the system's fflush to perform a cache refresh.

8: This section allows Zend to verify a script file to execute the state, judging permissions.

(not completed)

PHP Kernel: SAPI Quest

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.