internals:engine
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
internals:engine [2010/04/20 10:58] – derick | internals:engine [2017/09/22 13:28] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 8: | Line 8: | ||
* the pass_two() changes indexes into pointers so during execution they are accessible by: < | * the pass_two() changes indexes into pointers so during execution they are accessible by: < | ||
+ | ===== Objects ===== | ||
+ | See [[internals: | ||
===== FAQ ===== | ===== FAQ ===== | ||
Line 47: | Line 49: | ||
[11:59am] scoates: and the hashtable will automatically grow on _add, right? the length passed to init is just a hint? | [11:59am] scoates: and the hashtable will automatically grow on _add, right? the length passed to init is just a hint? | ||
[11:59am] johannes_: right | [11:59am] johannes_: right | ||
+ | ===== Unsorted ===== | ||
+ | Add your random stuff here. I'll move it/update it/fix it (Derick) | ||
+ | |||
+ | How to get %%__LINE__ and __FILE__%%? | ||
+ | * zend_get_executed_filename() and zend_get_executed_lineno() | ||
+ | |||
+ | How do I detect the SAPI? | ||
+ | * The fastest way [to detect CLI] would be: if (sapi_module.phpinfo_as_text) { ... } | ||
+ | * sapi_module is a true global, not a TSRM protected one | ||
+ | * sapi_module.name and sapi_module.pretty_name contain the name as char* | ||
+ | * sapi_module.phpinfo_as_text is a flag which can be set by different SAPIs to request text only phpinfo() output, currently only CLI and embed do that afaik, CGI does not. | ||
+ | |||
+ | |||
+ | ==== Extension Globals ===== | ||
+ | |||
+ | To use extension globals (which are either true globals or thread local globals, depending on whether ZTS is enabled), follow these steps: | ||
+ | |||
+ | - In php_extname.h, | ||
+ | |||
+ | < | ||
+ | ZEND_BEGIN_MODULE_GLOBALS(extname) | ||
+ | int var1; | ||
+ | char *var2; | ||
+ | .... | ||
+ | ZEND_END_MODULE_GLOBALS(extname) | ||
+ | </ | ||
+ | |||
+ | This will declare a structure (typedef' | ||
+ | |||
+ | - In php_extname.h, | ||
+ | |||
+ | - In php_extname.h, | ||
+ | < | ||
+ | #ifdef ZTS | ||
+ | # define EXTNAME_G(v) TSRMG(extname_globals_id, | ||
+ | #else | ||
+ | # define EXTNAME_G(v) (extname_globals.v) | ||
+ | #endif | ||
+ | </ | ||
+ | |||
+ | This will allow you to access the globals in a consistent manner in both ZTS and non-ZTS builds, like this: | ||
+ | |||
+ | < | ||
+ | |||
+ | - Now that you have declared the type that aggregates the globals and the variable that holds the globals, you must define the globals. In extname.c, add | ||
+ | |||
+ | < | ||
+ | |||
+ | This produces a tentative definition of extname_globals_id or extname_globals (depending on whether it's a ZTS or non-ZTS build). | ||
+ | |||
+ | - If you needn' | ||
+ | |||
+ | < | ||
+ | zend_module_entry extname_module_entry = { | ||
+ | ... | ||
+ | ZEND_MODULE_INFO_N(extname), | ||
+ | PHP_EXTNAME_VERSION, | ||
+ | ZEND_MODULE_GLOBALS(extname), | ||
+ | ZEND_MODULE_GLOBALS_CTOR_N(extname), | ||
+ | ZEND_MODULE_GLOBALS_DTOR_N(extname), | ||
+ | ... | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | Note: do not use ZEND_INIT_MODULE_GLOBALS/ | ||
+ | |||
+ | - Now define the constructor and destructor functions: | ||
+ | |||
+ | < | ||
+ | ZEND_MODULE_GLOBALS_CTOR_D(extname) | ||
+ | { | ||
+ | extname_globals-> | ||
+ | } | ||
+ | |||
+ | ZEND_MODULE_GLOBALS_DTOR_D(extname) | ||
+ | { | ||
+ | pefree(extname_globals-> | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | The globals constructor and destructor are NOT execute per-request, | ||
+ | |||
+ | Note: ZEND_MODULE_GLOBALS_CTOR_D will declare a function as receiving a zend_extname_globals*, |
internals/engine.txt · Last modified: 2017/09/22 13:28 by 127.0.0.1