PHP运行机制分析(多图)

Introduction

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++代码
  1. #include <php_embed.h>   
  2. int main (int argc, char *argv[]){   
  3. PHP_EMBED_START_BLOCK(argc, argv)   
  4. zend_eval_string(“echo „Hello World‟;”, NULL, “Embedded Code” TSRMLS_CC);   
  5. PHP_EMBED_END_BLOCK()   
  6. return 0;   
  7. }   

Lexer(flex)



Parser(bison)

Compiler

Opcode

C++代码
  1. struct zend_op {   
  2. opcode_handler_t handler;   
  3. znode result;   
  4. znode op1;   
  5. znode op2;   
  6. ulong extended_value;   
  7. uint lineno;   
  8. zend_uchar opcode;   
  9. };  

Executor

Cacher

Encoder / Decoder

Debugger

本文来源: Ben [email protected]

你可能感兴趣的:(C++,c,PHP,Flex,Zend)