SlideShare a Scribd company logo
PHP and Zend Internal I
    体系结构及生命周期



       夜沨@淘宝
Perface
• 研究内核不会一夜之间让你成为牛人
• PHP和Zend的源码并不是尽善尽美
• Not Only PHP
• 会谈方法论问题(例如何时何处适合使用
  PHP),不谈宗教问题(例如PHP和Lua哪
  个好),保持客观中立,我不是PHP布道
  者
• 干货,Talk Difference
Web编程断代史…
Web编程断代史…
• 静态页面时代

            GET /index.html HTTP/1.1 …

  Client                                 Web Server
            HTTP/1.1 200 OK …


                                                 本地I/O或socket




                                          Index.html
Web编程断代史…
• CGI时代

            GET /index.html?id=3 HTTP/1.1 …

   Client                                      Web Server
            HTTP/1.1 200 OK …


                                                       CGI - fork & execve


                                     socket
                      Database                CGI Application
Web编程断代史…
• 动态脚本时代

             GET /index.html?id=3 HTTP/1.1 …

    Client                                     Web Server
             HTTP/1.1 200 OK …


                                                       CGI - fork & execve



 Database
                      ?                        CGI Interface
                                                Application
走近一步看PHP…
走近一步看PHP…
• PHP和Zend的体系结构




                     CGI Interface
                      Application
        PHP Core


       Zend Engine
走近一步看PHP…
• PHP和Zend的体系结构

          PHP
             SAPI


           PHP Core


          Zend Engine
走近一步看PHP…
• PHP的执行流程
        SAPI                       PHP Core                 Zend Engine
  Startup
            Set HTTP Environment

            Start PHP Core
                                        MINIT
                                        RINIT
                                        Start Zend Engine
                                                                  Compile

                                                                  Execute

                                        RSHUTDOWN
                                        MSHUTDOWN
Shutdown
接口模式及生命周期模式…
接口模式及生命周期模式…
• CGI的困局 – One Request One Process

               GET /index.html?id=3 HTTP/1.1 …

      Client                                     Web Server
               HTTP/1.1 200 OK …


                                                       CGI - fork & execve



   Database
                     PHP                            SAPI
接口模式及生命周期模式…
• 新的接口模式

Web Server Extension – Apache mod_php


FastCGI – FPM
接口模式及生命周期模式…
• CGI/CLI

             Process Startup
                MINIT
                 RINIT
                SCRIPT
             RSHUTDOWN
             MSHUTDOWN
            Process Shutdown
接口模式及生命周期模式…
• Single Process Multirequest
                   Process Startup
                       MINIT
                        RINIT
                       SCRIPT
                    RSHUTDOWN
                         …
                       RINIT
                      SCRIPT
                   RSHUTDOWN
                   MSHUTDOWN
                  Process Shutdown
接口模式及生命周期模式…
• Multiprocess
     Process Startup    Process Startup    Process Startup
         MINIT              MINIT              MINIT
          RINIT              RINIT              RINIT
         SCRIPT             SCRIPT             SCRIPT
      RSHUTDOWN          RSHUTDOWN          RSHUTDOWN
           …                  …                  …
         RINIT              RINIT              RINIT
        SCRIPT             SCRIPT             SCRIPT
     RSHUTDOWN          RSHUTDOWN          RSHUTDOWN
     MSHUTDOWN          MSHUTDOWN          MSHUTDOWN
    Process Shutdown   Process Shutdown   Process Shutdown
接口模式及生命周期模式…
• Multithreaded
                   Process Startup
                       MINIT
          RINIT         RINIT            RINIT
         SCRIPT        SCRIPT           SCRIPT
      RSHUTDOWN     RSHUTDOWN        RSHUTDOWN




                   MSHUTDOWN
                  Process Shutdown
What is Next?
•   线程安全模型(ZTS & TSRM)
•   内核类型系统及表环境
•   垃圾回收机制(GC)
•   SAPI结构分析
•   PHP扩展模块开发
•   与内核相关的优化
•   OpCode
•   ……
Thanks 

  Q&A

More Related Content

PPTX
Node js feat pegasus
PPTX
Node.js中间件 connect模块深入浅出
PDF
Ruby rails分享
PPTX
Coffee script
PDF
Deployment With Subversion - Lorna Mitchell
 
PPT
PDF
ezComponents - Derick Rethans
 
PPT
Web2 0slideshare
Node js feat pegasus
Node.js中间件 connect模块深入浅出
Ruby rails分享
Coffee script
Deployment With Subversion - Lorna Mitchell
 
ezComponents - Derick Rethans
 
Web2 0slideshare

Similar to PHP and Zend Internal I - 体系结构及生命周期 (20)

KEY
phpconf 2012 yii
PPT
PHP WEB 应用组织与结构
KEY
Yiitalk
PPT
Php Webservers
PPT
Php Webservers
PDF
Phalcon phpconftw2012
PDF
Phalcon the fastest php framework 阿土伯
PDF
大话Php之性能
PDF
Phpconf 2011 introduction_to_codeigniter
PDF
多说沈振宇:插件思想及多说的开发实践
PDF
CodeIgniter 2.0.X
PDF
Think php 1.0.0rc1开发人员指南
PDF
Advanced php programming
PPT
腾讯大讲堂46 自由cgi之路v3
PPT
腾讯大讲堂46 自由cgi之路v3
PDF
Internal php and gdb php core
PPTX
Web并发模型粗浅探讨v3
PDF
Php调试技术手册发布(1.0.0 pdf)
PDF
-Nginx book
PDF
Douban qcon2009 beijing
phpconf 2012 yii
PHP WEB 应用组织与结构
Yiitalk
Php Webservers
Php Webservers
Phalcon phpconftw2012
Phalcon the fastest php framework 阿土伯
大话Php之性能
Phpconf 2011 introduction_to_codeigniter
多说沈振宇:插件思想及多说的开发实践
CodeIgniter 2.0.X
Think php 1.0.0rc1开发人员指南
Advanced php programming
腾讯大讲堂46 自由cgi之路v3
腾讯大讲堂46 自由cgi之路v3
Internal php and gdb php core
Web并发模型粗浅探讨v3
Php调试技术手册发布(1.0.0 pdf)
-Nginx book
Douban qcon2009 beijing
Ad

PHP and Zend Internal I - 体系结构及生命周期