日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關咨詢
選擇下列產(chǎn)品馬上在線溝通
服務時間:8:30-17:00
你可能遇到了下面的問題
關閉右側工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
PHP如何自定義擴展(三)之生命周期

接著上篇來講php生命周期。

10年的臺江網(wǎng)站建設經(jīng)驗,針對設計、前端、開發(fā)、售后、文案、推廣等六對一服務,響應快,48小時及時工作處理。營銷型網(wǎng)站建設的優(yōu)勢是能夠根據(jù)用戶設備顯示端的尺寸不同,自動調整臺江建站的顯示方式,使網(wǎng)站能夠適用不同顯示終端,在瀏覽器中調整網(wǎng)站的寬度,無論在任何一種瀏覽器上瀏覽網(wǎng)站,都能展現(xiàn)優(yōu)雅布局與設計,從而大程度地提升瀏覽體驗。成都創(chuàng)新互聯(lián)從事“臺江網(wǎng)站設計”,“臺江網(wǎng)站推廣”以來,每個客戶項目都認真落實執(zhí)行。

php_request_startup

這個階段和php_module_startup差不多,都是初始化工作,比php_module_startup簡單很多,可以自己看下,重點來看下執(zhí)行階段

php_execute_script

用gdb看看調用棧,gdb ./php

php_execute_script打斷點,執(zhí)行,在看下調用棧,

b php_execute_script
(gdb) r test.php
bt
#0  php_execute_script (primary_file=0x7fffffffe240)
    at /www/test/php/php-7.4.3/main/main.c:2541
#1  0x00000000008bbd85 in do_cli (argc=2, argv=0x1425af0)
    at /www/test/php/php-7.4.3/sapi/cli/php_cli.c:961
#2  0x00000000008bcd2d in main (argc=2, argv=0x1425af0)
    at /www/test/php/php-7.4.3/sapi/cli/php_cli.c:1356

在調用??梢郧宄吹綀?zhí)行流程,現(xiàn)在到/cli/php_cli.c文件看看做了哪些事情,

int c;
    zend_file_handle file_handle;
    int behavior = PHP_MODE_STANDARD;
    char *reflection_what = NULL;
    volatile int request_started = 0;
    volatile int exit_status = 0;
    char *php_optarg = NULL, *orig_optarg = NULL;
    int php_optind = 1, orig_optind = 1;
    char *exec_direct=NULL, *exec_run=NULL, *exec_begin=NULL, *exec_end=NULL;
    char *arg_free=NULL, **arg_excp=&arg_free;
    char *script_file=NULL, *translated_path = NULL;
    int interactive=0;
    int lineno = 0;
    const char *param_error=NULL;
    int hide_argv = 0;

    zend_try {

        CG(in_compilation) = 0; /* not initialized but needed for several options */

        while ((c = php_getopt(argc, argv, OPTIONS, &php_optarg, &php_optind, 0, 2)) != -1) {
            switch (c) {

初始化變量,解析命令到/main/main.c文件看看真正的執(zhí)行階段

PHPAPI int php_execute_script(zend_file_handle *primary_file)
{
    zend_file_handle *prepend_file_p, *append_file_p;
    zend_file_handle prepend_file = {{0}, NULL, NULL, 0, 0}, append_file = {{0}, NULL, NULL, 0, 0};
#if HAVE_BROKEN_GETCWD
    volatile int old_cwd_fd = -1;
#else
    char *old_cwd;
    ALLOCA_FLAG(use_heap)
#endif
    int retval = 0;

加載要執(zhí)行的php文件,通過zend_compile_file進行詞法分析 語法分析,生成AST,編譯成op_array,也就是指令集,
我們看下指令集,

b zend_execute
c
bt
(gdb) p *op_array
$1 = {type = 2 '\002', arg_flags = "\000\000", fn_flags = 37748736, 
  function_name = 0x0, scope = 0x0, prototype = 0x0, num_args = 0, 
  required_num_args = 0, arg_info = 0x0, cache_size = 16, last_var = 2, 
  T = 4, last = 13, opcodes = 0x7ffff5e8b000, run_time_cache__ptr = 0x0, 
  static_variables_ptr__ptr = 0x7ffff5e78358, static_variables = 0x0, 
  vars = 0x7ffff5e790f0, refcount = 0x7ffff5e85000, last_live_range = 0, 
  last_try_catch = 0, live_range = 0x0, try_catch_array = 0x0, 
  filename = 0x7ffff5e583c0, line_start = 1, line_end = 12, 
  doc_comment = 0x0, last_literal = 5, literals = 0x7ffff5e8b1a0, 
  reserved = {0x0, 0x0, 0x0, 0x0, 0x0, 0x0}}

然后放到zend虛擬機上執(zhí)行zend_execute(op_array, retval);這這里可以看到真正執(zhí)行的是這個zend_execute_ex(execute_data);,它是一個函數(shù)指針,我們可以更換它,知道這個,那么我們在寫擴展時可以重新寫個zend_execute_ex函數(shù)替換php默認的,我們自己的就可以做很多事情,像攔截php函數(shù),做性能監(jiān)控。

請求關閉階段php_request_shutdown,模塊關閉階段php_module_shutdown這兩個階段主要是做變量銷毀,現(xiàn)在我們知道了一個自定義擴展在生命周期里的怎么執(zhí)行的。


文章標題:PHP如何自定義擴展(三)之生命周期
URL鏈接:http://www.5511xx.com/article/dhjsppc.html