Php-fpm Execution Process source code analysis, php-fpm source code analysis
Author: zhanhailiang Date:
Sapi \ fpm \ fpm_main.c: @ main;
Fcgi_init ()-> fcgi_setup_signals (); set the signal processing method;
Sigaction (SIGUSR1, & new_sa, NULL );
Sigaction (SIGTERM, & new_sa, NULL );
Sigaction (SIGPIPE, NULL, & old_sa );
Sapi_startup (& cgi_sapi_module );
-> Sapi_globals_ctor (& sapi_globals); initialize the global variable;
-> Reentrancy_startup ();
Fcgi_fd = fpm_run (& max_requests); process initialization, call fork () to create a process
Fcgi_init_request (& request, fcgi_fd); request initialization;
While (fcgi_accept_request (& request)> = 0 ){
5.1. init_request_info; Request initialization; SG (request_info), SG (sapi_headers)
5.2. fpm_request_info ();
5.3. php_request_startup (TSRMLS_C );
-> Php_start_sapi (); Request global variable initialization;
-> Sapi_activate (TSRMLS_C); Request HTTP header information initialization;
-> Php_hash_environment (TSRMLS_C); initial listener to request environment variables; for example, $ _ GET, $ _ POST, $ _ ENV, $ _ SERVER, $ _ COOKIE, $ _ FILES is implemented in this step. $ _ REQUEST determines whether real-time Initialization is required based on jit_initialization;
5.4. fpm_status_handle_request (TSRMLS_C );
5.5. php_fopen_primary_script (& file_handle TSRMLS_CC); open the script;
5.5. fpm_request_executing ();
5.7. php_execute_script (& file_handle TSRMLS_CC); execute the script;
5.8. fpm_request_end (TSRMLS_C );
5.9. php_request_shutdown (void *) 0); The request ends and the resources applied in the request lifecycle are released;
Fcgi_shutdown (); release the applied persistent Resource