Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
The PHP Lifecycle
Yahoo! . 惠新宸
       Tel : 86111
       Mail: laruence@yahoo.com.cn
Summary

•   B/S(HTTP Request Cycle)
•   Apache Life Cycle
•   Apache Parse Request Cycle
•   PHP Life Cycle
•   Cooperati...
B/S




1. Client Request
2. Server Parse Requst and Send Response
3. Client interpret Responded Text/HTML/Json etc…
Apache Life Cycle
Apache Parse Request Cycle
PHP Life Cycle

•   In command line mode(CLI)
PHP Life Cycle con’t

•   PHP_MODULE_ENTRY(php_mysql.c 215 行 )
PHP Life Cycle con’t

•   PHP_MINIT_FUNCTION(php_mysql.c 378 行 )
PHP Life Cycle con’t

•   PHP_RINIT_FUNCTION(php_mysql.c 473 行 )
PHP Life Cycle con’t

•   PHP_SHUTDOWNS(php_mysql.c 403 行 )
PHP Life Cycle con’t

•   In DSO mode
     – Single process
PHP Life Cycle con’t

•   In DSO mode
     – Multiprocess
PHP Life Cycle con’t

•   In CGI mode
     – Multithreaded
Cooperation

•   Apache 1.3x + PHP 5.x in DSO mode
•   Dynamic Shared Objects (DSO)
    – mod_dso
        • src/modules/st...
Cooperation con’t

•   Php Module 注册 Handler
    – mod_php5.c 963 行
Cooperation con’t

•   Php Module 注册 Handler
    – mod_php5.c 987 行
Cooperation con’t

•   http.conf
PHP Parse/Execute Process
PHP Parse/Execute Process con’t

•   Scan(lex)
     –   Zend/zend_language_scanner.c 3047 行

    ZEND_API zend_op_array *c...
PHP Parse/Execute Process con’t

•   Parse/Complie(yacc)
     – zend_language_parser.y

     T_OPEN_TAG: '<?php '
     =  ...
PHP Parse/Execute Process con’t

•   Execute
    – Zend/zend_execute.c

     void (*zend_execute) (zend_op_array *op_array...
PHP Parse/Execute Process con’t

•   Execute
    – Zend/zend_opcode.c 428 行
A sample

•   Clien Request
A sample

•    http_main.c 8053
      –    main() call ap_main

•         ap_main => REALMAIN
      –    REALMAIN(argc, ar...
A sample

•   Server Pares
     – URI
        • Filename -> /test/index.php
    – User Auth
    – …
    – MIME type Check
...
A sample

• Zend/zend.c 1073 行
A sample


•   Index.php

        <?php
           echo 2+3;
        ?>
A sample

•   Zend_language_scanner.l 362 行




•   Zend_language_parse.c 62 行
A sample

•    Parser
      –   Zend_language_parse.y




      –   Zend_compile.c 258 行
A sample

•   Opcodes
A sample

•   Zend_execute       zend.c 594 行
     –   Zend_execute => execute
•   execute zend_vm_execute.h 34 行

       ...
Now We Can….

•   1, 服务器的 Access log 没有任何输出
•   2, 隐藏 PHP 文件类型
•   3, PHP 出错的阶段
•   4, 编写 PHP 扩展
•   5, …
Documents

•   《 Apache Server 源代码分析》
•   《 Writing Apache Modules with Perl and C 》
•   《 Extending and Embedding PHP 》
•...
谢谢大家!
Upcoming SlideShare
Loading in …5
×

The Php Life Cycle

24,956 views

Published on

Published in: Technology
  • go to this page:----http://books.google.co.in/books?id=nJWN1dyxaJIC&pg=PA390&lpg=PA390&dq=php+session+life+cycle&source=bl&ots=NwXKVV31i6&sig=Svb3WYjCrMA5EdrMeMpA6CGqVko&hl=en&ei=A44uTsreLYjTrQexgsG2Aw&sa=X&oi=book_result&ct=result&resnum=1&ved=0CBYQ6AEwADgK#v=onepage&q=php%20session%20life%20cycle&f=false
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here

The Php Life Cycle

  1. 1. The PHP Lifecycle Yahoo! . 惠新宸 Tel : 86111 Mail: laruence@yahoo.com.cn
  2. 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. 3. B/S 1. Client Request 2. Server Parse Requst and Send Response 3. Client interpret Responded Text/HTML/Json etc…
  4. 4. Apache Life Cycle
  5. 5. Apache Parse Request Cycle
  6. 6. PHP Life Cycle • In command line mode(CLI)
  7. 7. PHP Life Cycle con’t • PHP_MODULE_ENTRY(php_mysql.c 215 行 )
  8. 8. PHP Life Cycle con’t • PHP_MINIT_FUNCTION(php_mysql.c 378 行 )
  9. 9. PHP Life Cycle con’t • PHP_RINIT_FUNCTION(php_mysql.c 473 行 )
  10. 10. PHP Life Cycle con’t • PHP_SHUTDOWNS(php_mysql.c 403 行 )
  11. 11. PHP Life Cycle con’t • In DSO mode – Single process
  12. 12. PHP Life Cycle con’t • In DSO mode – Multiprocess
  13. 13. PHP Life Cycle con’t • In CGI mode – Multithreaded
  14. 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. 15. Cooperation con’t • Php Module 注册 Handler – mod_php5.c 963 行
  16. 16. Cooperation con’t • Php Module 注册 Handler – mod_php5.c 987 行
  17. 17. Cooperation con’t • http.conf
  18. 18. PHP Parse/Execute Process
  19. 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. 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. 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. 22. PHP Parse/Execute Process con’t • Execute – Zend/zend_opcode.c 428 行
  23. 23. A sample • Clien Request
  24. 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. 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. 26. A sample • Zend/zend.c 1073 行
  27. 27. A sample • Index.php <?php echo 2+3; ?>
  28. 28. A sample • Zend_language_scanner.l 362 行 • Zend_language_parse.c 62 行
  29. 29. A sample • Parser – Zend_language_parse.y – Zend_compile.c 258 行
  30. 30. A sample • Opcodes
  31. 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. 32. Now We Can…. • 1, 服务器的 Access log 没有任何输出 • 2, 隐藏 PHP 文件类型 • 3, PHP 出错的阶段 • 4, 编写 PHP 扩展 • 5, …
  33. 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. 34. 谢谢大家!

×