Author: goosman. lei blog: http://blog.csdn.net/lgg201mail: lgg860911@yahoo.com.cn-related code can refer to the <php extending and embedding> Chapter 12th, "Extension Globals" section. code for registering an extended global space: # ifdef ZTS ts_allocate_id (& sample_globals_id, sizeof (zend_sample_globals), (ts_allocate_ctor) samples (sample), (ts_allocate_dtor) Samples )); # else sample_globals_ctor (& sample_globals TSRMLS_CC); # endif writes a record to the resource_types_table array in the ts_allocate_id () function call. during the tsrm_shutdown () process, the registered dtor callback function is called. however, after coding according to the book, coredump will occur when running the test code. after tracking, we found that during the zend_shutdown () call process, we have already called DL_UNLOAD (module-> handle) for the module; as a result, the currently registered dtor is executing tsrm_shutdown () is no longer accessible. in addition, you can see ext/standard/file in the standard extension. c also uses this registration method. However, it should be static compilation, so there is no problem. my extension is compilation. so Dynamic Link. the following is the call path from zend_shutdown () to DL_UNLOAD. zend_shutdown () => zend_desctroy_modules () => modules () => zend_hash_apply_deleter () => module_destructor () => DL_UNLOAD ()