Home > Backend Development > PHP Tutorial > 07-Discuss again SAPI java api 1.8 Chinese version jquery api steam api64.dl

07-Discuss again SAPI java api 1.8 Chinese version jquery api steam api64.dl

WBOY
Release: 2016-07-29 08:52:17
Original
1637 people have browsed it

At each stage of the PHP life cycle, some service-related operations are implemented through the SAPI interface. The physical location of these built-in implementations is in the SAPI directory of the PHP source code. This directory stores PHP's code for each server abstraction layer, such as the implementation of the command line program, the implementation of Apache's mod_php module, the implementation of fastcgi, etc.

The same convention is followed between each server abstraction layer, here we call it the SAPI interface. Each SAPI implementation is a _sapi_module_struct structure variable. (SAPI interface). In the PHP source code, when server-related information needs to be called, it is all implemented by calling the corresponding method in the SAPI interface, and the corresponding method will have its own implementation when each server abstraction layer is implemented.

The following is a simple diagram for SAPI:


sap2000 api,api原油数据公布,api原油库存,美国api原油数据,api,api数据对原油影响,原油里什么是api,百度地图api,api是什么,steam api.dll,api接口,java api,java api 1.8中文版,jquery api,steam api64.dl

Taking cgi mode and apache2 server as an example, their startup methods are as follows:

<code>cgi_sapi_module.startup(&cgi_sapi_module)   //  cgi模式 cgi/cgi_main.c文件

apache2_sapi_module.startup(&apache2_sapi_module);
 //  apache2服务器  apache2handler/sapi_apache2.c文件
</code>
Copy after login

The cgi_sapi_module here is a static variable of the sapi_module_struct structure. Its startup method points to the php_cgi_startup function pointer. In addition to the startup function pointer, there are many other methods or fields in this structure. Some of its definitions are as follows:

<code>struct _sapi_module_struct {
    char *name;         //  名字(标识用)
    char *pretty_name;  //  更好理解的名字(自己翻译的)

    int (*startup)(struct _sapi_module_struct *sapi_module);    //  启动函数
    int (*shutdown)(struct _sapi_module_struct *sapi_module);   //  关闭方法

    int (*activate)(TSRMLS_D);  // 激活
    int (*deactivate)(TSRMLS_D);    //  停用

    int (*ub_write)(const char *str, unsigned int str_length TSRMLS_DC);
     //  不缓存的写操作(unbuffered write)
    void (*flush)(void *server_context);    //  flush
    struct stat *(*get_stat)(TSRMLS_D);     //  get uid
    char *(*getenv)(char *name, size_t name_len TSRMLS_DC); //  getenv

    void (*sapi_error)(int type, const char *error_msg, ...);   /* error handler */

    int (*header_handler)(sapi_header_struct *sapi_header, sapi_header_op_enum op,
        sapi_headers_struct *sapi_headers TSRMLS_DC);   /* header handler */

     /* send headers handler */
    int (*send_headers)(sapi_headers_struct *sapi_headers TSRMLS_DC);

    void (*send_header)(sapi_header_struct *sapi_header,
            void *server_context TSRMLS_DC);   /* send header handler */

    int (*read_post)(char *buffer, uint count_bytes TSRMLS_DC); /* read POST data */
    char *(*read_cookies)(TSRMLS_D);    /* read Cookies */

    /* register server variables */
    void (*register_server_variables)(zval *track_vars_array TSRMLS_DC);

    void (*log_message)(char *message);     /* Log message */
    time_t (*get_request_time)(TSRMLS_D);   /* Request Time */
    void (*terminate_process)(TSRMLS_D);    /* Child Terminate */

    char *php_ini_path_override;    //  覆盖的ini路径

    ...
    ...
};
</code>
Copy after login

The above structures are defined in the interface implementation of each server. As defined by Apache2:

<code>static sapi_module_struct apache2_sapi_module = {
    "apache2handler",
    "Apache 2.0 Handler",

    php_apache2_startup,                /* startup */
    php_module_shutdown_wrapper,            /* shutdown */

    ...
}
</code>
Copy after login

Many of the SAPI implementations built into PHP are no longer maintained or have become somewhat non-mainstream. The PHP community is currently considering moving some SAPIs out of the code base. The community considers many features to be in the PECL library unless they are really necessary, or some features are almost universal. For example, the very popular APC cache extension will enter the core code base.

The entire SAPI is similar to an application of the template method pattern in object-oriented. Some functions included in the SAPI.c and SAPI.h files are abstract templates in the template method pattern, and each server's definition and related implementation of sapi_module is a specific template.

Such a structure is used in many places in PHP source code. For example, in PHP extension development, each extension needs to define a zend_module_entry structure. The function of this structure is similar to the sapi_module_struct structure, which is an application similar to the template method pattern. In the life cycle of PHP, if you need to call an extension, the methods it calls are the methods specified in the zend_module_entry structure. As mentioned in the previous section, when executing the request initialization of each extension, request_startup_func is called uniformly. method, and in the definition of each extension, the function corresponding to request_startup_func is specified through the macro PHP_RINIT. Take the VLD extension as an example: its request is initialized as PHP_RINIT(vld), corresponding to which the extension needs to have the implementation of this function:

<code>PHP_RINIT_FUNCTION(vld) {
}
</code>
Copy after login

So, we also need to implement these interfaces of the extension when writing the extension. Similarly, when implementing Each server interface also needs to implement its corresponding SAPI.

').addClass('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i ').text(i)); }; $numbering.fadeIn(1700); }); });

The above has introduced 07-Discussing SAPI again, including api and sap content. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template