Home  >  Article  >  Backend Development  >  PHP SAPI interface

PHP SAPI interface

WBOY
WBOYOriginal
2016-08-08 09:32:321106browse
Generally, the entire workflow of FastCGI is like this:
  • Load the FastCGI process manager (IIS ISAPI or Apache Module) when the Web Server starts
  • The FastCGI process manager initializes itself and starts multiple CGI interpreter processes (Multiple php-cgi visible) and wait for the connection from the Web Server.
  • When a client request reaches 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.
  • After the FastCGI sub-process completes processing, it returns standard output and error information to the Web Server from the same connection. When the FastCGI child process closes the connection, the request is processed. The FastCGI child process then waits for and handles the next connection from the FastCGI process manager (running in the Web Server). In CGI mode, php-cgi exits at this point.
  • PHP’s CGI implements the Fastcgi protocol. It is a TCP or UDP protocol server that accepts requests from the Web server. When it is started, it creates a socket listener for the TCP/UDP protocol server and receives related requests for processing. Then the life cycle of PHP is entered: module initialization, sapi initialization, processing of PHP requests, module closing, sapi closing, etc. constitute the entire CGI life cycle.
    rrree
    static sapi_module_struct cgi_sapi_module = {
    	"cgi-fcgi",						/* name */
    	"CGI/FastCGI",					/* pretty name */
    
    	php_cgi_startup,				/* startup */
    	php_module_shutdown_wrapper,	/* shutdown */
    
    	sapi_cgi_activate,				/* activate */
    	sapi_cgi_deactivate,			/* deactivate */
    
    	sapi_cgi_ub_write,				/* unbuffered write */
    	sapi_cgi_flush,					/* flush */
    	NULL,							/* get uid */
    	sapi_cgi_getenv,				/* getenv */
    
    	php_error,						/* error handler */
    
    	NULL,							/* header handler */
    	sapi_cgi_send_headers,			/* send headers handler */
    	NULL,							/* send header handler */
    
    	sapi_cgi_read_post,				/* read POST data */
    	sapi_cgi_read_cookies,			/* read Cookies */
    
    	sapi_cgi_register_variables,	/* register server variables */
    	sapi_cgi_log_message,			/* Log message */
    	NULL,							/* Get request time */
    	NULL,							/* Child terminate */
    
    	STANDARD_SAPI_MODULE_PROPERTIES
    };

    The above has introduced the PHP SAPI interface, including aspects of it. I hope it will be helpful to friends who are interested in PHP tutorials.

    Statement:
    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
    Previous article:How to use yii2 sessionNext article:How to use yii2 session