SlideShare a Scribd company logo
1 of 34
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
•   Cooperating with Apache
•   PHP Parse/Execute Process
•   Now We Can…


         Linux/Unix + Apache 1.3x + PHP 5.x
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/standard/mod_so.c 347 行
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 *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: '?>'
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: '?>'
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;
                                 };
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, 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
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);
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 行

         ZEND_API void execute(zend_op_array *op_array TSRMLS_DC)


•   Generate Output
•   Return to Apache Server process
•   Server send Responds Text to Client.
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 》
•   《 PHP 手册》:“ Zend API :深入 PHP 内核”
•    http://blog.csdn.net/laruence
谢谢大家!

More Related Content

What's hot

Lecture 2
Lecture 2Lecture 2
Lecture 2
Mr SMAK
 
8 queens problem using back tracking
8 queens problem using back tracking8 queens problem using back tracking
8 queens problem using back tracking
Tech_MX
 
Processes and Threads in Windows Vista
Processes and Threads in Windows VistaProcesses and Threads in Windows Vista
Processes and Threads in Windows Vista
Trinh Phuc Tho
 
Unit 3 principles of programming language
Unit 3 principles of programming languageUnit 3 principles of programming language
Unit 3 principles of programming language
Vasavi College of Engg
 

What's hot (20)

Code Optimization
Code OptimizationCode Optimization
Code Optimization
 
Processes and threads
Processes and threadsProcesses and threads
Processes and threads
 
Lecture 2
Lecture 2Lecture 2
Lecture 2
 
Theory of Computation
Theory of ComputationTheory of Computation
Theory of Computation
 
Android User Interface
Android User InterfaceAndroid User Interface
Android User Interface
 
Operating systems system structures
Operating systems   system structuresOperating systems   system structures
Operating systems system structures
 
8 queens problem using back tracking
8 queens problem using back tracking8 queens problem using back tracking
8 queens problem using back tracking
 
Hypothetical machine and instruction flow scenarios
Hypothetical machine and instruction flow scenariosHypothetical machine and instruction flow scenarios
Hypothetical machine and instruction flow scenarios
 
cpu scheduling
cpu schedulingcpu scheduling
cpu scheduling
 
Lecture 14 run time environment
Lecture 14 run time environmentLecture 14 run time environment
Lecture 14 run time environment
 
Process management in linux
Process management in linuxProcess management in linux
Process management in linux
 
Design Patterns - Compiler Case Study - Hands-on Examples
Design Patterns - Compiler Case Study - Hands-on ExamplesDesign Patterns - Compiler Case Study - Hands-on Examples
Design Patterns - Compiler Case Study - Hands-on Examples
 
Principles of computer design
Principles of computer designPrinciples of computer design
Principles of computer design
 
process control block
process control blockprocess control block
process control block
 
Java Servlets
Java ServletsJava Servlets
Java Servlets
 
ELEMENTS OF TRANSPORT PROTOCOL
ELEMENTS OF TRANSPORT PROTOCOLELEMENTS OF TRANSPORT PROTOCOL
ELEMENTS OF TRANSPORT PROTOCOL
 
Processes and Threads in Windows Vista
Processes and Threads in Windows VistaProcesses and Threads in Windows Vista
Processes and Threads in Windows Vista
 
Parallel processing and pipelining
Parallel processing and pipeliningParallel processing and pipelining
Parallel processing and pipelining
 
Unit 3 principles of programming language
Unit 3 principles of programming languageUnit 3 principles of programming language
Unit 3 principles of programming language
 
Single instruction multiple data
Single instruction multiple dataSingle instruction multiple data
Single instruction multiple data
 

Similar to The Php Life Cycle

Phpをいじり倒す10の方法
Phpをいじり倒す10の方法Phpをいじり倒す10の方法
Phpをいじり倒す10の方法
Moriyoshi Koizumi
 
Anatomy of a PHP Request ( UTOSC 2010 )
Anatomy of a PHP Request ( UTOSC 2010 )Anatomy of a PHP Request ( UTOSC 2010 )
Anatomy of a PHP Request ( UTOSC 2010 )
Joseph Scott
 
Php opcodes sep2008
Php opcodes sep2008Php opcodes sep2008
Php opcodes sep2008
bengiuliano
 
DPC 2012 : PHP in the Dark Workshop
DPC 2012 : PHP in the Dark WorkshopDPC 2012 : PHP in the Dark Workshop
DPC 2012 : PHP in the Dark Workshop
Jeroen Keppens
 
Symfony 2 (PHP Quebec 2009)
Symfony 2 (PHP Quebec 2009)Symfony 2 (PHP Quebec 2009)
Symfony 2 (PHP Quebec 2009)
Fabien Potencier
 
Tips
TipsTips
Tips
mclee
 

Similar to The Php Life Cycle (20)

Phpをいじり倒す10の方法
Phpをいじり倒す10の方法Phpをいじり倒す10の方法
Phpをいじり倒す10の方法
 
Cli the other sapi pbc11
Cli the other sapi pbc11Cli the other sapi pbc11
Cli the other sapi pbc11
 
CLI, the other SAPI phpnw11
CLI, the other SAPI phpnw11CLI, the other SAPI phpnw11
CLI, the other SAPI phpnw11
 
Cli the other SAPI confoo11
Cli the other SAPI confoo11Cli the other SAPI confoo11
Cli the other SAPI confoo11
 
Anatomy of a PHP Request ( UTOSC 2010 )
Anatomy of a PHP Request ( UTOSC 2010 )Anatomy of a PHP Request ( UTOSC 2010 )
Anatomy of a PHP Request ( UTOSC 2010 )
 
Quick tour of PHP from inside
Quick tour of PHP from insideQuick tour of PHP from inside
Quick tour of PHP from inside
 
Php engine
Php enginePhp engine
Php engine
 
PHP Internals and Virtual Machine
PHP Internals and Virtual MachinePHP Internals and Virtual Machine
PHP Internals and Virtual Machine
 
Php opcodes sep2008
Php opcodes sep2008Php opcodes sep2008
Php opcodes sep2008
 
Create your own PHP extension, step by step - phpDay 2012 Verona
Create your own PHP extension, step by step - phpDay 2012 VeronaCreate your own PHP extension, step by step - phpDay 2012 Verona
Create your own PHP extension, step by step - phpDay 2012 Verona
 
Debugging: Rules And Tools - PHPTek 11 Version
Debugging: Rules And Tools - PHPTek 11 VersionDebugging: Rules And Tools - PHPTek 11 Version
Debugging: Rules And Tools - PHPTek 11 Version
 
[2012 CodeEngn Conference 06] pwn3r - Secuinside 2012 CTF 예선 문제풀이
[2012 CodeEngn Conference 06] pwn3r - Secuinside 2012 CTF 예선 문제풀이[2012 CodeEngn Conference 06] pwn3r - Secuinside 2012 CTF 예선 문제풀이
[2012 CodeEngn Conference 06] pwn3r - Secuinside 2012 CTF 예선 문제풀이
 
PHP & Performance
PHP & PerformancePHP & Performance
PHP & Performance
 
DPC 2012 : PHP in the Dark Workshop
DPC 2012 : PHP in the Dark WorkshopDPC 2012 : PHP in the Dark Workshop
DPC 2012 : PHP in the Dark Workshop
 
Symfony 2 (PHP Quebec 2009)
Symfony 2 (PHP Quebec 2009)Symfony 2 (PHP Quebec 2009)
Symfony 2 (PHP Quebec 2009)
 
Performance tuning with zend framework
Performance tuning with zend frameworkPerformance tuning with zend framework
Performance tuning with zend framework
 
Quality assurance for php projects with PHPStorm
Quality assurance for php projects with PHPStormQuality assurance for php projects with PHPStorm
Quality assurance for php projects with PHPStorm
 
Debugging: Rules & Tools
Debugging: Rules & ToolsDebugging: Rules & Tools
Debugging: Rules & Tools
 
"Развитие ветки PHP-7"
"Развитие ветки PHP-7""Развитие ветки PHP-7"
"Развитие ветки PHP-7"
 
Tips
TipsTips
Tips
 

More from Xinchen Hui (12)

A brief to PHP 7.3
A brief to PHP 7.3A brief to PHP 7.3
A brief to PHP 7.3
 
PHP7.1 New Features & Performance
PHP7.1 New Features & PerformancePHP7.1 New Features & Performance
PHP7.1 New Features & Performance
 
The secret of PHP7's Performance
The secret of PHP7's Performance The secret of PHP7's Performance
The secret of PHP7's Performance
 
PHP7 - For Its Best Performance
PHP7 - For Its Best PerformancePHP7 - For Its Best Performance
PHP7 - For Its Best Performance
 
A History of PHP
A History of PHPA History of PHP
A History of PHP
 
High Performance Solution for PHP7
High Performance Solution for PHP7High Performance Solution for PHP7
High Performance Solution for PHP7
 
PHP7 - The New Engine for old good train
PHP7 - The New Engine for old good trainPHP7 - The New Engine for old good train
PHP7 - The New Engine for old good train
 
微博Lamp性能优化之路(2014)
微博Lamp性能优化之路(2014)微博Lamp性能优化之路(2014)
微博Lamp性能优化之路(2014)
 
Weibo lamp improvements
Weibo lamp improvementsWeibo lamp improvements
Weibo lamp improvements
 
Php 5.4 performance
Php 5.4 performancePhp 5.4 performance
Php 5.4 performance
 
China PHP Technology Summit 2011 ppt
China PHP Technology Summit 2011 pptChina PHP Technology Summit 2011 ppt
China PHP Technology Summit 2011 ppt
 
Php performance
Php performancePhp performance
Php performance
 

Recently uploaded

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 

Recently uploaded (20)

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 

The Php Life Cycle

  • 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…
  • 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 行
  • 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);
  • 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