歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> Linux編程 >> Zend 引擎執行器的核心代碼

Zend 引擎執行器的核心代碼

日期:2017/3/1 9:37:39   编辑:Linux編程

Zend 引擎執行器的核心代碼

ZEND_API void execute(zend_op_array *op_array TSRMLS_DC)
{
// 初始化執行上下文
zend_execute_data execute_data;

// 如果有異常就退出執行
if (EG(exception)) {
return;
}

/* Initialize execute_data */
EX(fbc) = NULL; // 初始化正在調用的函數
EX(object) = NULL; // 初始化正在調用的對象
EX(old_error_reporting) = NULL; // 初始化錯誤報告變量

// 為執行棧分配空間
if (op_array->T < TEMP_VAR_STACK_LIMIT) {
EX(Ts) = (temp_variable *) do_alloca(sizeof(temp_variable) * op_array->T);
} else {
EX(Ts) = (temp_variable *) safe_emalloc(sizeof(temp_variable), op_array->T, 0);
}
// 為臨時變量分配空間並初始化這些空間
EX(CVs) = (zval***)do_alloca(sizeof(zval**) * op_array->last_var);
memset(EX(CVs), 0, sizeof(zval**) * op_array->last_var);

EX(op_array) = op_array;

// 切換執行上下文
EX(original_in_execution) = EG(in_execution);
EX(symbol_table) = EG(active_symbol_table);
EX(prev_execute_data) = EG(current_execute_data); // 將當前全局變量中的執行數據壓棧
EG(current_execute_data) = &execute_data; // 將當前執行上下文壓棧

EG(in_execution) = 1;
// 初始化第一個指令(opcode)
/*
#define ZEND_VM_SET_OPCODE(new_op) \
CHECK_SYMBOL_TABLES() \
EX(opline) = new_op

execute_data.opline 為當前執行的 opcode
*/
if (op_array->start_op) {
ZEND_VM_SET_OPCODE(op_array->start_op);
} else {
ZEND_VM_SET_OPCODE(op_array->opcodes);
}

if (op_array->uses_this && EG(This)) {
EG(This)->refcount++; /* For $this pointer */
if (zend_hash_add(EG(active_symbol_table), "this", sizeof("this"), &EG(This), sizeof(zval *), NULL)==FAILURE) {
EG(This)->refcount--;
}
}

// 將存儲opline的內存地址賦給 executor_globals.online_ptr ,可以實時跟蹤opcode的執行
EG(opline_ptr) = &EX(opline);

EX(function_state).function = (zend_function *) op_array;
EG(function_state_ptr) = &EX(function_state);
#if ZEND_DEBUG
/* function_state.function_symbol_table is saved as-is to a stack,
* which is an intentional UMR. Shut it up if we're in DEBUG.
*/
EX(function_state).function_symbol_table = NULL;
#endif

while (1) {
#ifdef ZEND_WIN32
if (EG(timed_out)) {
zend_timeout(0);
}
#endif

// 循環調用每個opline的 handler 函數,如果是推出函數的話,返回值大於0,就退出
if (EX(opline)->handler(&execute_data TSRMLS_CC) > 0) {
return;
}

}
zend_error_noreturn(E_ERROR, "Arrived at end of main loop which shouldn't happen");
}

CentOS 6.3 安裝LNMP (PHP 5.4,MyySQL5.6) http://www.linuxidc.com/Linux/2013-04/82069.htm

在部署LNMP的時候遇到Nginx啟動失敗的2個問題 http://www.linuxidc.com/Linux/2013-03/81120.htm

Ubuntu安裝Nginx php5-fpm MySQL(LNMP環境搭建) http://www.linuxidc.com/Linux/2012-10/72458.htm

《細說PHP》高清掃描PDF+光盤源碼+全套教學視頻 http://www.linuxidc.com/Linux/2014-03/97536.htm

PHP 的詳細介紹:請點這裡
PHP 的下載地址:請點這裡

Copyright © Linux教程網 All Rights Reserved