首页 PHP运行机制初探

PHP运行机制初探

举报
开通vip

PHP运行机制初探 http://www.yAnbiN.org PHP 运行机制初探 Ben ben.yan@msn.com http://www.yAnbiN.org Introduction .php SAPI Compiler Executor Opcodes Output Buffer • IE/Firefox • Console • Host • Apache • CLI • Embed • Lexer • Parser • Main Script • Function Table ...

PHP运行机制初探
http://www.yAnbiN.org PHP 运行机制初探 Ben ben.yan@msn.com http://www.yAnbiN.org Introduction .php SAPI Compiler Executor Opcodes Output Buffer • IE/Firefox • Console • Host • Apache • CLI • Embed • Lexer • Parser • Main Script • Function Table • Class Table • Include file • Switch/Call/Goto • 129 Operators http://www.yAnbiN.org Apache Mime type handler  AddType application/x-httpd-php .php  AddType application/x-httpd-php-source .phps  Server context  Override php.ini (php_value, php_flag, etc)  Environment variables(PHP_SELF, etc)  Create Child Process/Thread http://www.yAnbiN.org Apache Mime type handler  AddType application/x-httpd-php .php  AddType application/x-httpd-php-source .phps  Server context  Override php.ini (php_value, php_flag, etc)  Environment variables(PHP_SELF, etc)  Create Child Process/Thread http://www.yAnbiN.org CLI (command line interface) CLI ≈ CGI SAPI differences  start up in quiet mode by default  plain text error message(no http header)  implicit_flush always on  max_execution_time is set to unlimited  others http://www.yAnbiN.org Embed Embed = Mini CLI php5embed .lib example.c #include int main (int argc, char *argv[]){ PHP_EMBED_START_BLOCK(argc, argv) zend_eval_string(“echo „Hello World‟;”, NULL, “Embedded Code” TSRMLS_CC); PHP_EMBED_END_BLOCK() return 0; } http://www.yAnbiN.org Lexer(flex) T_OPEN_TAG: '' source: Zend/zend_language_scanner.l http://www.yAnbiN.org Parser(bison) Opcode Op1 Op2 Result ADD 1 2 $tmp0 ASSIGN $cv0(sum) $tmp0 $var1 CONCAT '1+2=' $cv0(sum) $tmp2 ECHO $tmp2 RETURN 1 source: Zend/zend_language_parser.y T_OPEN_TAG: '' http://www.yAnbiN.org Compiler Opcode Op1 Op2 Result ADD 1 2 $tmp0 ASSIGN $cv0(sum) $tmp0 $var1 CONCAT '1+2=' $cv0(sum) tmp2 ECHO $tmp2 RETURN 1 zend_op_array *(*zend_compile_file)(zend_file_handle *file_handle, int type TSRMLS_DC); http://www.yAnbiN.org struct zend_op { opcode_handler_t handler; znode result; znode op1; znode op2; ulong extended_value; uint lineno; zend_uchar opcode; }; Opcode http://www.yAnbiN.org Executor PHP 4.x switch (opcode){ case ZEND_ADD: break; case ZEND_CALL: break; …. } PHP 5.2 call ZEND_ADD_HANDLER() PHP 5.2 switch ( case ZEND_ADD: goto: zend_add ) zend_add: // CALL GOTOSWITCH void (*zend_execute)(zend_op_array *op_array TSRMLS_DC); http://www.yAnbiN.org Cacher Opcodes Cacher Compiler Executor •APC •eAcclerator •XCache •Zend Platform PHP_MINIT_FUNCTION(xxx){ old_compile_file = zend_compile_file; zend_compile_file = xxx_compile_file;; } http://www.yAnbiN.org Encoder / Decoder Opcodes Encoder Decoder Compiler Executor •ZendGuard • ionCube •eAcclerator Encoder NOT Encoder, BUT Obfuscator! http://www.yAnbiN.org Debugger PHP_MINIT_FUNCTION(xxx){ old_ execute = zend_ execute; zend_ execute = xxx_ execute; } struct zend_extension { message_handler_func_t message_handler; op_array_handler_func_t op_array_handler; statement_handler_func_t statement_handler; fcall_begin_handler_func_t fcall_begin_handler; fcall_end_handler_func_t fcall_end_handler; op_array_ctor_func_t op_array_ctor; op_array_dtor_func_t op_array_dtor; } http://www.yAnbiN.org Question ? http://www.yAnbiN.org
本文档为【PHP运行机制初探】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑, 图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
该文档来自用户分享,如有侵权行为请发邮件ishare@vip.sina.com联系网站客服,我们会及时删除。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。
本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。
网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。
下载需要: 免费 已有0 人下载
最新资料
资料动态
专题动态
is_958044
暂无简介~
格式:pdf
大小:439KB
软件:PDF阅读器
页数:16
分类:互联网
上传时间:2011-12-05
浏览量:23