Table of Contents
Request processing of two major processes in PHP core
Home Backend Development PHP Tutorial Request processing of two major processes in PHP kernel_PHP tutorial

Request processing of two major processes in PHP kernel_PHP tutorial

Jul 13, 2016 am 10:13 AM
Kernel

Request processing of two major processes in PHP core

static int php_handler(request_rec *r)
{
	/* Initiliaze the context */
        php_struct * volatile ctx;
        void *conf;
        apr_bucket_brigade * volatile brigade;
        apr_bucket *bucket;
        apr_status_t rv;
        request_rec * volatile parent_req = NULL;
        TSRMLS_FETCH();

	......

        zend_file_handle zfd;

        zfd.type = ZEND_HANDLE_FILENAME;
        zfd.filename = (char *) r->filename;
        zfd.free_filename = 0;
        zfd.opened_path = NULL;

	zend_execute_scripts(ZEND_INCLUDE TSRMLS_CC, NULL, 1, &zfd);

	......
}

ZEND_API int zend_execute_scripts(int type TSRMLS_DC, zval **retval, int file_count, ...) /* {{{ */
{
	......

	EG(active_op_array) = \
	zend_compile_file(file_handle, type TSRMLS_CC);

	......

	zend_execute(EG(active_op_array) TSRMLS_CC);

	......
}

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; // 初始化错误报告变量  
      
    // 为执行栈分配空间  
&#160; &#160; if (op_array->T < TEMP_VAR_STACK_LIMIT) { &#160;
&#160; &#160; &#160; &#160; EX(Ts) = (temp_variable *) do_alloca(sizeof(temp_variable) * op_array->T); &#160;
&#160; &#160; } else { &#160;
&#160; &#160; &#160; &#160; EX(Ts) = (temp_variable *) safe_emalloc(sizeof(temp_variable), op_array->T, 0); &#160;
&#160; &#160; } &#160;
&#160; &#160; // 为临时变量分配空间并初始化这些空间 &#160;
&#160; &#160; EX(CVs) = (zval***)do_alloca(sizeof(zval**) * op_array->last_var); &#160;
&#160; &#160; memset(EX(CVs), 0, sizeof(zval**) * op_array->last_var); &#160;
&#160; &#160; &#160;&#160;
&#160; &#160; EX(op_array) = op_array; &#160;
&#160; &#160; &#160;&#160;
&#160; &#160; // 切换执行上下文 &#160;
&#160; &#160; EX(original_in_execution) = EG(in_execution); &#160;
&#160; &#160; EX(symbol_table) = EG(active_symbol_table); &#160;
&#160; &#160; EX(prev_execute_data) = EG(current_execute_data); // 将当前全局变量中的执行数据压栈 &#160;
&#160; &#160; EG(current_execute_data) = &execute_data; // 将当前执行上下文压栈 &#160;
&#160;&#160;
&#160; &#160; EG(in_execution) = 1; &#160;
&#160; &#160; // 初始化第一个指令(opcode) &#160;
&#160; &#160; /*&#160;
&#160; &#160; #define ZEND_VM_SET_OPCODE(new_op) \&#160;
&#160; &#160; CHECK_SYMBOL_TABLES() \&#160;
&#160; &#160; EX(opline) = new_op&#160;
&#160; &#160; &#160;
&#160; &#160; execute_data.opline 为当前执行的 opcode&#160;
&#160; &#160; */ &#160;
&#160; &#160; if (op_array->start_op) { &#160;
&#160; &#160; &#160; &#160; ZEND_VM_SET_OPCODE(op_array->start_op); &#160;
&#160; &#160; } else { &#160;
&#160; &#160; &#160; &#160; ZEND_VM_SET_OPCODE(op_array->opcodes); &#160;
&#160; &#160; } &#160;
&#160;&#160;
&#160; &#160; if (op_array->uses_this && EG(This)) { &#160;
&#160; &#160; &#160; &#160; EG(This)->refcount++; /* For $this pointer */ &#160;
&#160; &#160; &#160; &#160; if (zend_hash_add(EG(active_symbol_table), "this", sizeof("this"), &EG(This), sizeof(zval *), NULL)==FAILURE) { &#160;
&#160; &#160; &#160; &#160; &#160; &#160; EG(This)->refcount--; &#160;
&#160; &#160; &#160; &#160; } &#160;
&#160; &#160; } &#160;
&#160;&#160;
&#160; &#160; // 将存储opline的内存地址赋给 executor_globals.online_ptr ,可以实时跟踪opcode的执行 &#160;
&#160; &#160; EG(opline_ptr) = &EX(opline); &#160;
&#160;&#160;
&#160; &#160; EX(function_state).function = (zend_function *) op_array; &#160;
&#160; &#160; EG(function_state_ptr) = &EX(function_state); &#160;
#if ZEND_DEBUG &#160;
&#160; &#160; /* function_state.function_symbol_table is saved as-is to a stack,&#160;
&#160; &#160; &#160;* which is an intentional UMR. &#160;Shut it up if we&#39;re in DEBUG.&#160;
&#160; &#160; &#160;*/ &#160;
&#160; &#160; EX(function_state).function_symbol_table = NULL; &#160;
#endif &#160;
&#160; &#160; &#160;&#160;
&#160; &#160; while (1) { &#160;
#ifdef ZEND_WIN32 &#160;
&#160; &#160; &#160; &#160; if (EG(timed_out)) { &#160;
&#160; &#160; &#160; &#160; &#160; &#160; zend_timeout(0); &#160;
&#160; &#160; &#160; &#160; } &#160;
#endif &#160;
&#160; &#160; &#160; &#160; &#160;&#160;
&#160; &#160; &#160; &#160; // 循环调用每个opline的 handler 函数,如果是推出函数的话,返回值大于0,就退出 &#160;
&#160; &#160; &#160; &#160; if (EX(opline)->handler(&execute_data TSRMLS_CC) > 0) { &#160;
&#160; &#160; &#160; return; &#160;
&#160; &#160; &#160; &#160; } &#160;
&#160;&#160;
&#160; &#160; } &#160;
&#160; &#160; zend_error_noreturn(E_ERROR, "Arrived at end of main loop which shouldn&#39;t happen"); &#160;
} &#160;
Copy after login

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/914780.htmlTechArticleRequest processing of the two major processes in the PHP core static int php_handler(request_rec *r){/* Initiliaze the context */ php_struct * volatile ctx; void *conf; apr_bucket_brigade * volatile brigad...
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1662
14
PHP Tutorial
1261
29
C# Tutorial
1234
24
How to install the Linux kernel on Ubuntu 22.04 Detailed tutorial! How to install the Linux kernel on Ubuntu 22.04 Detailed tutorial! Mar 01, 2024 pm 10:34 PM

To install the Linux kernel on Ubuntu22.04, you can follow the following steps: Update the system: First, make sure your Ubuntu system is the latest, execute the following command to update the system package: sudoaptupdatesudoaptupgrade Download the kernel file: Visit the official Linux kernel website () to download Required kernel version. Select a stable version and download the source code file (with .tar.gz or .tar.xz extension), for example: wget Unzip the file: Use the following command to unzip the downloaded kernel source code file: tar-xflinux-5.14.tar. xz install build dependencies: Install the tools and dependencies required to build the kernel. Execute

Modify Linux kernel startup sequence Modify Linux kernel startup sequence Feb 23, 2024 pm 10:22 PM

Modify the kernel startup sequence of Linux 1. Modify the kernel startup sequence of RHEL6/CentOS6. Check the /etc/grub.conf file to determine the system kernel situation. According to the document, there are two kernel versions in the system, namely 2.6.32-573.18.1.el6.x86_64 and 2.6.32-431.23.3.el6.x86_64. Kernel versions are listed from top to bottom. In the grub.conf file, you can decide which kernel version to use when the system starts by adjusting the default parameters. The default value is 0, which means the system will boot the latest kernel version. A value of 0 corresponds to the first content listed in the grub.conf file.

Is the Android system based on the Linux kernel? Is the Android system based on the Linux kernel? Mar 14, 2024 pm 03:12 PM

Is the Android system based on the Linux kernel? Android system, as one of the most widely used mobile operating systems in the world, has always been said to be developed based on the Linux kernel. However, what is the real situation? Let’s explore this issue. First, let's understand the Linux kernel. The Linux kernel, as an open source operating system kernel, was first released by Linus Torvalds in 1991. It provides a good foundation for many operating systems, including And

Linux kernel main function analysis and analysis Linux kernel main function analysis and analysis Mar 14, 2024 am 11:27 AM

Linux kernel main function analysis and analysis The Linux kernel is a large and complex system, in which the main function plays a vital role. It is the entry point of the entire system and is responsible for initializing various subsystems, drivers and kernel modules. Finally start the entire operating system. This article will analyze and analyze the main function of the Linux kernel, and demonstrate its key functions and execution flow through specific code examples. In the Linux kernel, the entry point of the main function is start_k in the init/main.c file.

Explore the programming languages ​​used under the hood of the Linux kernel Explore the programming languages ​​used under the hood of the Linux kernel Mar 20, 2024 am 08:06 AM

Title: Exploring the programming language used at the bottom of the Linux kernel. As an open source, stable and reliable operating system kernel, the Linux kernel has a wide range of applications in the computer field. To have an in-depth understanding of the Linux kernel, you have to involve the programming language used at the bottom. In fact, the Linux kernel is mainly written in C language, which is an efficient, flexible and easy-to-maintain programming language that is very suitable for operating system development. This article will explore the bottom of the Linux kernel from a detailed perspective

Detailed explanation of Linux kernel source code storage location Detailed explanation of Linux kernel source code storage location Mar 14, 2024 pm 06:12 PM

Detailed explanation of the storage location of Linux kernel source code. Linux kernel source code is the core part of the Linux operating system. It contains the implementation code for various functions of the operating system. To understand where the Linux kernel source code is stored, we first need to understand the organizational structure of the Linux kernel. Linux kernel source code is usually stored in the /usr/src/linux or /usr/src/linux- directory. In this directory, there are many

Is the performance of win10 improved compared to win7? Detailed introduction Is the performance of win10 improved compared to win7? Detailed introduction Dec 23, 2023 am 09:04 AM

The more popular system now is the win10 system. Of course, there are also users who are preparing to upgrade. What these users are most concerned about is whether the performance of win10 is improved compared to win7? In fact, overall there are still some improvements, and the compatibility is also good. Is the performance of win10 improved compared to win7? Answer: The performance of win10 is improved compared to win7. The overall improvement is not very big, because the performance is mainly linked to the hardware. However, the win10 system has undergone a lot of optimizations so it can provide better assistance. Moreover, Microsoft no longer supports win7 updates, so win10 will be the most common system in the future. Comparative features of win10 compared to win7: 1. Configuration: win7 has been launched for more than ten years and has gone through a lot.

Debian installation kernel and Debian installation kernel first header file Debian installation kernel and Debian installation kernel first header file Feb 14, 2024 pm 01:24 PM

Preface LINUX, this open source operating system, has always provided a stable and powerful environment for developers around the world. Whether it is servers, embedded devices, or even supercomputers, Linux plays a key role. In order to meet the needs of different To meet the needs, we often need to customize and install the Linux kernel. We will take the Debian system as an example to discuss how to install the kernel and kernel header files. Debian Installing the Kernel In a Debian system, installing a new kernel is relatively straightforward and can be done through the apt command. You need to update your package list. Run the following command: ```sqlsudoapt-getupdate```. You can use the following command to install the new kernel. Kernel: s

See all articles