The global Space code for registering extensions is as follows:
#ifdef zts ts_allocate_id (&sample_globals_id, sizeof (Zend_sample_globals), (ts_allocate_ctor) Zend_module_ Globals_ctor_n (sample), (Ts_allocate_dtor) zend_module_globals_dtor_n (sample); #else Sample_globals_ctor (& Sample_globals tsrmls_cc); #endif
In the ts_allocate_id () function call, a record is written to the resource_types_table array.
In the process of Tsrm_shutdown (), the registered Dtor callback function is invoked.
But after I've coded the book, I'll run the test code with Coredump.
Following the discovery, the Dl_unload (Module->handle) has been called on the module during the Zend_shutdown () call process. The handle that was registered at that time (Dtor) was not accessible when executing tsrm_shutdown ().
At the same time, see the ext/standard/file.c in the standard extension also has this kind of registration method to use, however, it should be statically compiled so there is no problem. And my extension is compiled. So dynamic link.
The following is the call path to trace Zend_shutdown () eventually to Dl_unload ().
Zend_shutdown () => zend_desctroy_modules () => Zend_hash_graceful_reverse_destroy () => zend_hash_apply_ Deleter () => module_destructor () => dl_unload ()