The Php Life Cycle

Loading...

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

0 comments

Post a comment

    Post a comment
    Embed Video
    Edit your comment Cancel

    1 Favorite

    The Php Life Cycle - Presentation Transcript

    1. The PHP Lifecycle Yahoo! . 惠新宸 Tel : 86111 Mail: laruence@yahoo.com.cn
    2. Summary • B/S(HTTP Request Cycle) • Apache Life Cycle • Apache Parse Request Cycle • PHP Life Cycle • Cooperating with Apache • PHP Parse/Execute Process • Now We Can… Linux/Unix + Apache 1.3x + PHP 5.x
    3. B/S 1. Client Request 2. Server Parse Requst and Send Response 3. Client interpret Responded Text/HTML/Json etc…
    4. Apache Life Cycle
    5. Apache Parse Request Cycle
    6. PHP Life Cycle • In command line mode(CLI)
    7. PHP Life Cycle con’t • PHP_MODULE_ENTRY(php_mysql.c 215 行 )
    8. PHP Life Cycle con’t • PHP_MINIT_FUNCTION(php_mysql.c 378 行 )
    9. PHP Life Cycle con’t • PHP_RINIT_FUNCTION(php_mysql.c 473 行 )
    10. PHP Life Cycle con’t • PHP_SHUTDOWNS(php_mysql.c 403 行 )
    11. PHP Life Cycle con’t • In DSO mode – Single process
    12. PHP Life Cycle con’t • In DSO mode – Multiprocess
    13. PHP Life Cycle con’t • In CGI mode – Multithreaded
    14. Cooperation • Apache 1.3x + PHP 5.x in DSO mode • Dynamic Shared Objects (DSO) – mod_dso • src/modules/standard/mod_so.c 347 行
    15. Cooperation con’t • Php Module 注册 Handler – mod_php5.c 963 行
    16. Cooperation con’t • Php Module 注册 Handler – mod_php5.c 987 行
    17. Cooperation con’t • http.conf
    18. PHP Parse/Execute Process
    19. PHP Parse/Execute Process con’t • Scan(lex) – Zend/zend_language_scanner.c 3047 行 ZEND_API zend_op_array *compile_file(zend_file_handle *file_handle, int type TSRMLS_DC){ retval = op_array; …. return retval;} – Zend/zend_language_scanner.l T_OPEN_TAG: '<?php ' = <?php T_LNUMBER: '1' $sum = 1 + 2; + echo “1+2=“.$sum; T_LNUMBER: '2' ?> T_ECHO: 'echo'' T_CONSTANT_ENCAPSED_STRI NG: ''1+2=''. T_CLOSE_TAG: '?>'
    20. PHP Parse/Execute Process con’t • Parse/Complie(yacc) – zend_language_parser.y T_OPEN_TAG: '<?php ' = Opcode Op1 Op2 Result T_LNUMBER: '1' ADD 1 2 $tmp0 + ASSIGN $cv0(sum) $tmp0 $var1 T_LNUMBER: '2' CONCAT '1+2=' $cv0(sum) $tmp2 T_ECHO: 'echo'' ECHO $tmp2 T_CONSTANT_ENCAPSED_STRI RETURN 1 NG: ''1+2=''. T_CLOSE_TAG: '?>'
    21. PHP Parse/Execute Process con’t • Execute – Zend/zend_execute.c void (*zend_execute) (zend_op_array *op_array TSRMLS_DC); • Zend_op_array – Zend/zend_compile.h struct zend_op{ opcode_handler_t handler; znoderesult; znodeop1; znodeop2; ulongextended_value; uintlineno; zend_ucharopcode; };
    22. PHP Parse/Execute Process con’t • Execute – Zend/zend_opcode.c 428 行
    23. A sample • Clien Request
    24. A sample • http_main.c 8053 – main() call ap_main • ap_main => REALMAIN – REALMAIN(argc, argv) – http_main.c • child_main – Call child_sub_main 6134 • chile_sub_main – loop worker – call ap_process_request(r) on request • http_reqeust.c 1308 • ap_process_request – call process_request_internal • process_request_internal – call ap_invoke_handler Application/x-httpd-php -> send_parsed_php
    25. A sample • Server Pares – URI • Filename -> /test/index.php – User Auth – … – MIME type Check • application/x-httpd-http – Call handler • send_parsed_php(request_rec *) • Zend_execute_script(…..request_rec->filename);
    26. A sample • Zend/zend.c 1073 行
    27. A sample • Index.php <?php echo 2+3; ?>
    28. A sample • Zend_language_scanner.l 362 行 • Zend_language_parse.c 62 行
    29. A sample • Parser – Zend_language_parse.y – Zend_compile.c 258 行
    30. A sample • Opcodes
    31. A sample • Zend_execute zend.c 594 行 – Zend_execute => execute • execute zend_vm_execute.h 34 行 ZEND_API void execute(zend_op_array *op_array TSRMLS_DC) • Generate Output • Return to Apache Server process • Server send Responds Text to Client.
    32. Now We Can…. • 1, 服务器的 Access log 没有任何输出 • 2, 隐藏 PHP 文件类型 • 3, PHP 出错的阶段 • 4, 编写 PHP 扩展 • 5, …
    33. Documents • 《 Apache Server 源代码分析》 • 《 Writing Apache Modules with Perl and C 》 • 《 Extending and Embedding PHP 》 • 《 PHP 手册》:“ Zend API :深入 PHP 内核” • http://blog.csdn.net/laruence
    34. 谢谢大家!

    + Laruence HuiLaruence Hui, 4 months ago

    custom

    380 views, 1 favs, 0 embeds more stats

    More info about this document

    © All Rights Reserved

    Go to text version

    • Total Views 380
      • 380 on SlideShare
      • 0 from embeds
    • Comments 0
    • Favorites 1
    • Downloads 0
    Most viewed embeds

    more

    All embeds

    less

    Flagged as inappropriate Flag as inappropriate
    Flag as inappropriate

    Select your reason for flagging this presentation as inappropriate. If needed, use the feedback form to let us know more details.

    Cancel
    File a copyright complaint
    Having problems? Go to our helpdesk?

    Categories

    Tags