PHP-FPM implementation Process Source analysis

Source: Internet
Author: User
Author: zhanhailiang Date: 2015-03-09

SAPI\FPM\FPM\FPM_MAIN.C: @main;

  1. Fcgi_init ()->fcgi_setup_signals (); Set up the signal processing method;

    Sigaction (SIGUSR1, &new_sa, NULL);
    Sigaction (SIGTERM, &new_sa, NULL);
    Sigaction (Sigpipe, NULL, &old_sa);

  2. Sapi_startup (&cgi_sapi_module);
    ->sapi_globals_ctor (&sapi_globals); Initialize global variables;
    ->reentrancy_startup ();

  3. FCGI_FD = Fpm_run (&max_requests); Process initialization, calling fork () to create a process

  4. Fcgi_init_request (&request, FCGI_FD); Request initialization;

  5. 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); Request environment variable initial listening; such as $_get,$_post,$_env,$_server,$_cookie,$_files is in this step to start; $_request based on Jit_initialization to determine whether real-time initialization is required;
    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, releasing the requested resource in the request life cycle;

  6. Fcgi_shutdown (); Release a persisted resource for the request

  • 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.