珀耳塞福建 发表于 2017-3-24 11:14:00

PHP运行机制分析(多图)

  Introduction
http://koyoz.com/blog/attachments/date_200808/thumb_bfdc6e55947cec148c7c22fe7cb7153c.jpg
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
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
Embed
Embed  = Mini CLI

php5embed .lib
example.c 
C++代码

[*]#include <php_embed.h>   
[*]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;   
[*]}   

Lexer(flex)
http://koyoz.com/blog/attachments/date_200808/thumb_4b76e5c1dfef50def94d231953c031a5.jpg

Parser(bison)
http://koyoz.com/blog/attachments/date_200808/thumb_6e0ca851ac923a393c23cdee60fd359a.jpg
Compiler
http://koyoz.com/blog/attachments/date_200808/thumb_78fea4fe95299f10bc82b1acde4a9c8b.jpg
Opcode
C++代码

[*]struct zend_op {   
[*]opcode_handler_t handler;   
[*]znode result;   
[*]znode op1;   
[*]znode op2;   
[*]ulong extended_value;   
[*]uint lineno;   
[*]zend_uchar opcode;   
[*]};  

Executor
http://koyoz.com/blog/attachments/date_200808/thumb_9ea57a2a32b5747f5ef7c853e29a0af5.jpg
Cacher
http://koyoz.com/blog/attachments/date_200808/6e42e19f1208d3d2912d74894ed1b6df.jpg
Encoder / Decoder
http://koyoz.com/blog/attachments/date_200808/c93f6753926d561e1eb47240cd64f53c.jpg
Debugger
http://koyoz.com/blog/attachments/date_200808/a6be62d93e229d022aa796892bebd34d.jpg
本文来源: Ben ben.yan@msn.com
页: [1]
查看完整版本: PHP运行机制分析(多图)