o 1 php n é - pic.huodongjia.com · 3 5 2013.7-2014.3 360 ï ¼ l ´ • o ' x r þ 1 ¦ ^ d...
TRANSCRIPT
PHP @
l
l PHP7
l PHP-AOP Memcached Go
l GitHub:https://github.com/pangudashu
l 1
l 2 PHP
l 3 PHP
PHP ……
1 l 2011 PHP
l CMS discuz ecshop…
l html …
l PHP…
2 l “ ”-
……
l
l C Sql Server …
l -> -> ->
l 2 get PHPthinkphp…
l …
So Easy?
3 2013.7-2014.3 360 l
• MemcachedMysql Linux PHP Smarty MVC Nginx
…
•
l @
4 2014.7-2015.11
l API
l CURD CURD CURD…
l …
1
?
1
l
l
l
l
l
l
l
l ThinkPHP MVC
l Memcached TCP /
/ - IO
l Yaf PHP / /
l Beego PHP
源码只是看看就行了? NO!
2
l
•
l
•
l
•
•
•
l Yaf
l QFrame ThinkPHP PHP So Easy!
l Memcached TCP No Problem
l Beego Go
……
4
l CURD CURD CURD
…… l
…
l
l
l
2015.11 l
……
l
l …
困惑2: PHP
2017.4
l PHP Golang C++
l Go • Gc • • • PHP
l
•
PHP
•
• ==
• Go/C++ PHP
• PHP
3 PHP
l PHP swoole
l PHP PHP
l PHP bug https://bugs.php.net/
l PHP go defer…
https://wiki.php.net/rfc/
l …
l “ ”PHP PHP
或许可以这样:
为什么要看内核?
l
l
l PHP
executor
ZEND_FE_RESET_R
循环体statement
ZEND_JMPNZ
empty
foreach后语句
ZEND_FE_FETCH_R
ZEND_ASSIGN
ZEND_FE_FREE
end
内核怎么看? l PHP sapi php zend ext...
l zend PHP
l PHP
l gdb
l
5、内核探索 l PHP
SAPI
main
ExtensionRun-Time Compiler Executor
ZendVm
1
浏览器
2
3 4
6
5
PHP
• SAPI
• PHP web
• Zend VM PHP
• PHP/Zend
l
php_request_startup()请求初始化阶段
php_module_startup()模块初始化阶段
php_module_shutdown()模块关闭阶段
php_request_shutdown()请求关闭阶段
php_execute_script()执行脚本阶段
main()
l — struct _zval_struct { zend_value value; /* value */ union { struct { ZEND_ENDIAN_LOHI_4( zend_uchar type, /* active type */ zend_uchar type_flags, zend_uchar const_flags, zend_uchar reserved) /* call info for EX(This) */ } v; uint32_t type_info; } u1; union { uint32_t var_flags; uint32_t next; /* hash collision chain */ uint32_t cache_slot; /* literal cache slot */ uint32_t lineno; /* line number (for ast nodes) */ uint32_t num_args; /* arguments number for EX(This) */ uint32_t fe_pos; /* foreach position */ uint32_t fe_iter_idx; /* foreach iterator index */ } u2; };
• zval zend_value
• double long bool value
• zend_array zend_string
zend_object zend_resource
zend_reference
• 16byte
zend_value u1uint32_t
0 8 12 16
l
•
• value value
• 0 value
• • 0 value
$a = array(1); //a -> zend_array_1(refcount=1)
$b = $a; //a b -> zend_array_1(refcount=2)
$b[] = 2; //a -> zend_array_1(refcount=1)
//b -> zend_array_2(refcount=1)
var_dump($a);
dup
l PHP
opline
Call opcode
AST
ZEND_ASSIGN
ZEND_ECHO
ZEND_RETURN
PHP
1
PHP -----> AST -------> opcodes
<?php $a = “hi, PHP!”; echo $a;
ZEND_AST_STMT_LIST根节点
ZEND_AST_ASSIGN ZEND_AST_ECHO
ZEND_AST_VAR$a
ZEND_AST_ZVAL“hi,PHP!” …
123
…
$a
…
ZEND_ASSIGN 0xffxx 0xffxx
op1
op2…
局部变量区
literals
ZEND_ECHO
ZEND_RETURN
zend_op_array
2
CALL GOTO SWITCH
CALL
LOOP
CALL HANDLER
END
zend_execute_data *execute_data = ex;
while (1) {
int ret;
//
if (UNEXPECTED((ret = ((opcode_handler_t)execute_data->opline->handler
)(execute_data)) != 0)) {
if (EXPECTED(ret > 0)) {
execute_data = EG(current_execute_data);
} else {
return;
}
}
}
不止于此 l
• • • if else switch • do while while for foreach • break goto • try catch • Include require • …
l ZendMM l TSRM l Opcache JIT l ……
学习资料 l http://www.laruence.com/
l http://nikic.github.io/
l http://www.phpinternalsbook.com/
l https://github.com/pangudashu/php7-internal
l Or
Thanks
Q&A
PHPCON www.phpconchina.com PPT https://github.com/ThinkDevelopers/PHPConChina
QQ 34449228 135615537 ThinkInLAMP