深入PHP内核之全局变量

在阅读PHP源码的时候,会遇到很多诸如:CG(),EG() ,PG(),FG()这样的宏,如果不了解这些宏的意义,会给理解源码造成很大困难

EG()、这个宏可以用来访问符号表,函数,资源信息和常量

CG() 用来访问核心全局变量

PG() PHP全局变量。我们知道php.ini会映射一个或者多个PHP全局结构。举几个使用这个宏的例子:PG(register_globals), PG(safe_mode), PG(memory_limit)

FG() 文件全局变量。大多数文件I/O或相关的全局变量的数据流都塞进标准扩展出口结构。

申明 Zend/zend_globals_macros.h

typedef struct _zend_compiler_globals zend_compiler_globals;
typedef struct _zend_executor_globals zend_executor_globals;

/* Compiler */
#ifdef ZTS
# define CG(v) TSRMG(compiler_globals_id, zend_compiler_globals *, v)
int zendparse(void *compiler_globals);
#else
# define CG(v) (compiler_globals.v)
extern ZEND_API struct _zend_compiler_globals compiler_globals;
int zendparse(void);
#endif

/* Executor */
#ifdef ZTS
# define EG(v) TSRMG(executor_globals_id, zend_executor_globals *, v)
#else
# define EG(v) (executor_globals.v)
extern ZEND_API zend_executor_globals executor_globals;
#endif

 结构体中的具体定义 Zend/zend_globals.h

/* Define ZTS if you want a thread-safe Zend */
/*#undef ZTS*/

#ifdef ZTS

BEGIN_EXTERN_C()
ZEND_API extern int compiler_globals_id;
ZEND_API extern int executor_globals_id;
END_EXTERN_C()

#endif

 struct _zend_compiler_globals

struct _zend_compiler_globals {
        zend_stack bp_stack;
        zend_stack switch_cond_stack;
        zend_stack foreach_copy_stack;
        zend_stack object_stack;
        zend_stack declare_stack;

        zend_class_entry *active_class_entry;

        /* variables for list() compilation */
        zend_llist list_llist;
        zend_llist dimension_llist;
        zend_stack list_stack;

        zend_stack function_call_stack;

        char *compiled_filename;

        int zend_lineno;

        zend_op_array *active_op_array;

        HashTable *function_table;      /* function symbol table */
        HashTable *class_table;         /* class table */

        HashTable filenames_table;

        HashTable *auto_globals;

        zend_bool parse_error;
        zend_bool in_compilation;
        zend_bool short_tags;
        zend_bool asp_tags;

        zend_declarables declarables;

        zend_bool unclean_shutdown;

        zend_bool ini_parser_unbuffered_errors;

        zend_llist open_files;

        long catch_begin;

        struct _zend_ini_parser_param *ini_parser_param;

        int interactive;

        zend_uint start_lineno;
        zend_bool increment_lineno;

        znode implementing_class;

        zend_uint access_type;

        char *doc_comment;
        zend_uint doc_comment_len;

        zend_uint compiler_options; /* set of ZEND_COMPILE_* constants */

        zval      *current_namespace;
        HashTable *current_import;
        HashTable *current_import_function;
        HashTable *current_import_const;
        zend_bool  in_namespace;
        zend_bool  has_bracketed_namespaces;

        HashTable const_filenames;

        zend_compiler_context context;
        zend_stack context_stack;

        /* interned strings */
        char *interned_strings_start;
        char *interned_strings_end;
        char *interned_strings_top;
        char *interned_strings_snapshot_top;
#ifndef ZTS
        char *interned_empty_string;
#endif

        HashTable interned_strings;

        const zend_encoding **script_encoding_list;
        size_t script_encoding_list_size;
        zend_bool multibyte;
        zend_bool detect_unicode;
        zend_bool encoding_declared;

#ifdef ZTS
        zval ***static_members_table;
        int last_static_member;
#endif
};

struct _zend_executor_globals

struct _zend_executor_globals {
        zval **return_value_ptr_ptr;

        zval uninitialized_zval;
        zval *uninitialized_zval_ptr;

        zval error_zval;
        zval *error_zval_ptr;

        /* symbol table cache */
        HashTable *symtable_cache[SYMTABLE_CACHE_SIZE];
        HashTable **symtable_cache_limit;
        HashTable **symtable_cache_ptr;

        zend_op **opline_ptr;

        HashTable *active_symbol_table;
        HashTable symbol_table;         /* main symbol table */

        HashTable included_files;       /* files already included */

        JMP_BUF *bailout;

        int error_reporting;
        int orig_error_reporting;
        int exit_status;

        zend_op_array *active_op_array;

        HashTable *function_table;      /* function symbol table */
        HashTable *class_table;         /* class table */
        HashTable *zend_constants;      /* constants table */

        zend_class_entry *scope;
        zend_class_entry *called_scope; /* Scope of the calling class */

        zval *This;

        long precision;

        int ticks_count;

        zend_bool in_execution;
        HashTable *in_autoload;
        zend_function *autoload_func;
        zend_bool full_tables_cleanup;

        /* for extended information support */
        zend_bool no_extensions;

#ifdef ZEND_WIN32
        zend_bool timed_out;
        OSVERSIONINFOEX windows_version_info;
#endif

        HashTable regular_list;
        HashTable persistent_list;

        zend_vm_stack argument_stack;

        int user_error_handler_error_reporting;
        zval *user_error_handler;
        zval *user_exception_handler;
        zend_stack user_error_handlers_error_reporting;
        zend_ptr_stack user_error_handlers;
        zend_ptr_stack user_exception_handlers;

        zend_error_handling_t  error_handling;
        zend_class_entry      *exception_class;

        /* timeout support */
        int timeout_seconds;

        int lambda_count;

        HashTable *ini_directives;
        HashTable *modified_ini_directives;
        zend_ini_entry *error_reporting_ini_entry;

        zend_objects_store objects_store;
        zval *exception, *prev_exception;
        zend_op *opline_before_exception;
        zend_op exception_op[3];

        struct _zend_execute_data *current_execute_data;

        struct _zend_module_entry *current_module;

        zend_property_info std_property_info;

        zend_bool active;

        zend_op *start_op;

        void *saved_fpu_cw_ptr;
#if XPFPA_HAVE_CW
        XPFPA_CW_DATATYPE saved_fpu_cw;
#endif

        void *reserved[ZEND_MAX_RESERVED_RESOURCES];
};

一般EG用的比较多

时间: 2025-01-01 23:23:43

深入PHP内核之全局变量的相关文章

十天学Linux内核之第五天---有关Linux文件系统实现的问题

有时间睡懒觉了,却还是五点多醒了,不过一直躺倒九点多才算起来,昨晚一直在弄飞凌的嵌入式开发板,有些问题没解决,自己电脑系统的问题,虽然Win10发布了,,但我还是好喜欢XP呀,好想回家用用家里的XP来玩玩这块板子,不知不觉也第五天了,感觉代码都有些模糊,连自己都不是很清楚了,担心现在分享起来比较困惑,各路大神多加批评呀,觉得渣渣的尽量指正出来,拉出来批评,今天还是来总结一下有关Linux文件系统的问题吧~ Linux的使用和用户空间程序的编程和文件系统有着密切的关系,文件系统的概念大家应该都有些

4.内核定时器的使用

下面代码是本人在项目中遇到使用定时器的一个例子,可以编译运行正确的结果 1 #include <linux/timer.h> 2 3 struct timer_list timer; //内核定时器全局变量 4 5 void timer_init() //放在适当的地方,以便被正确地调用 6 { 7 timer.data = 0; 8 timer.expires = jiffies + 1*HZ; 9 timer.function = (int* )timer_handler; 10 add_

wxWidgets第十四课 wxTimer定时器

说明 OnIdle CPU空闲的情况下处理消息,如果需要定时功能,就需要使用定时器wxTimer 问题 比如定时器函数运行耗时10秒,定时的时间是10毫秒,是否是每隔10毫秒执行一次定时器函数,还是等待定时器函数运行结束,才开始重新计时 结果 在定时器函数中执行::Sleep(10000);等待10秒,发现实际上需要等待定时器函数执行结束,才开始重新计时.所以在如下的场景需要特别小心:需要定时读取数据,而读取数据之后,执行一大堆耗时的操作,这个时候,就需要启动线程去处理,而不能在定时器函数中完成

【转】2012年7月12 – 腾讯公司 WEB高级应用开发工程师 最新面试题

腾讯面试(WEB高级应用开发工程师<PHP>)非答案啊!!! 开始正题之前,容博主啰嗦两句吧,呵呵.(你也可跳过直接到红色字体看题!) 腾讯一直是我很敬重的企业,尽管小企鹅在战略上饱受争议,正面的,负面的我就不一一列举了,但又怎样?在中国,他还是能如微软一样,渗透到每一个用户的日常生活中去,这样的成绩,恐怕在世界范围内也没有多少吧!想进去自然困难丛丛,面试周期达一个月之久.技术面试只占四分之一,剩下的都是人品关!我勒个去!你知道技术对鄙人还算凑活,可这RP,我是一直持保留意见的!不过话说回来,

PHP内核中重要的两个全局变量

在阅读PHP源码的时候,会遇到很多诸如:CG(),EG() 这样的宏,如果不了解这些宏的意义,会给理解源码造成很大困难. Zend引擎中有两个重要的全局变量结构体,就是Zend引擎关闭之前都会存在的变量: typedef struct _zend_compiler_globals zend_compiler_globals; typedef struct _zend_executor_globals zend_executor_globals; /* Compiler */ #ifdef ZTS

php内核解析(四)全局变量

这里阅读的php版本为PHP-7.1.0 RC3,阅读代码的平台为linux CG CG是从全局的compiler_global中获取属性值,里面存储的就是编译过程使用到的全局变量. struct _zend_compiler_globals { zend_stack loop_var_stack; zend_class_entry *active_class_entry; zend_string *compiled_filename; int zend_lineno; zend_op_arra

arm-linux内存管理学习笔记(2)-内核临时页表的建立

学习了arm内存页表的工作原理,接下来就开始咱们软件工程师的本职工作,对内核相关代码进行分析.内核代码那么复杂,该从哪里下手呢,想来想去.其实不管代码逻辑如何复杂,最终的落脚点都是在对页表项的操作上,那么内核是在什么时机会对页表项进行操作,如何操作? 对于一个页表项,抛开所有的软件复杂逻辑,操作无非就是2种吧.一是填写更新页表项,二是读取获取页表项. MMU负责根据页表项进行虚实地址转换,因此读取获取页表项的工作是MMU硬件完成,软件是不参与的.内核代码的主体工作是来更新内存页表.页表更新的时机

linux内核探索之内存管理(二):linux系统中的内存组织--结点、内存域和页帧

本文主要参考<深入linux内核架构>(3.2节)及Linux3.18.3内核源码 概述:本文主要描述了内存管理相关的数据结构:结点pg_data_t.内存域struct zone以及页帧(物理页):struct page ,以及该结构相关的一些基本概念. 1. 概述 内存划分为接点,每个结点关联到系统中的一个处理器,在内核中表示为pg_data_t. 各个结点又划分为内存域,比如DMA内存域,高端内存域,普通内存域. 内核内存域的宏: enum zone_type { #ifdef CONF

linux内核并发情景

通过<linux内核并发基本概念>,我们看到了,对于并发访问共享资源,造成的运行结果与预期的不一致问题,这样的结果是软件设计者不能允许的.我们知道,我们编写一个软件一定是需要软件实现特定的功能,如果我们在设计的时候,期望得到结果A,但实际软件运行中却得到的结果B,那么这个软件是相当糟糕的,因此,对于并发引起的竞态,是我们在设计内核和驱动软件时,必须要留意的. 在<linux内核并发基本概念>中,通过一个简单的并发的场景,引出了竞态.共享资源和临界区等概念.接下来,本文就linux内