@@ -118,6 +118,8 @@ static bool dd_has_other_observers;
118
118
static int dd_observer_extension_backup = -1 ;
119
119
#endif
120
120
121
+ datadog_php_sapi ddtrace_active_sapi ;
122
+
121
123
_Atomic(int64_t ) ddtrace_warn_legacy_api ;
122
124
123
125
ZEND_DECLARE_MODULE_GLOBALS (ddtrace )
@@ -571,7 +573,7 @@ static PHP_GSHUTDOWN_FUNCTION(ddtrace) {
571
573
zai_hook_gshutdown ();
572
574
573
575
#ifdef CXA_THREAD_ATEXIT_WRAPPER
574
- if (!dd_is_main_thread ) {
576
+ if (!dd_is_main_thread && ddtrace_active_sapi != DATADOG_PHP_SAPI_FRANKENPHP ) {
575
577
dd_run_rust_thread_destructors (NULL );
576
578
}
577
579
#endif
@@ -983,8 +985,8 @@ static void dd_register_fatal_error_ce(void) {
983
985
ddtrace_ce_fatal_error = zend_register_internal_class_ex (& ce , zend_ce_exception );
984
986
}
985
987
986
- static bool dd_is_compatible_sapi (datadog_php_string_view module_name ) {
987
- switch (datadog_php_sapi_from_name ( module_name ) ) {
988
+ static bool dd_is_compatible_sapi () {
989
+ switch (ddtrace_active_sapi ) {
988
990
case DATADOG_PHP_SAPI_APACHE2HANDLER :
989
991
case DATADOG_PHP_SAPI_CGI_FCGI :
990
992
case DATADOG_PHP_SAPI_CLI :
@@ -1000,8 +1002,7 @@ static bool dd_is_compatible_sapi(datadog_php_string_view module_name) {
1000
1002
}
1001
1003
1002
1004
static void dd_disable_if_incompatible_sapi_detected (void ) {
1003
- datadog_php_string_view module_name = datadog_php_string_view_from_cstr (sapi_module .name );
1004
- if (UNEXPECTED (!dd_is_compatible_sapi (module_name ))) {
1005
+ if (UNEXPECTED (!dd_is_compatible_sapi ())) {
1005
1006
LOG (WARN , "Incompatible SAPI detected '%s'; disabling ddtrace" , sapi_module .name );
1006
1007
DDTRACE_G (disable ) = 1 ;
1007
1008
}
@@ -1010,10 +1011,14 @@ static void dd_disable_if_incompatible_sapi_detected(void) {
1010
1011
static PHP_MINIT_FUNCTION (ddtrace ) {
1011
1012
UNUSED (type );
1012
1013
1014
+ ddtrace_active_sapi = datadog_php_sapi_from_name (datadog_php_string_view_from_cstr (sapi_module .name ));
1015
+
1013
1016
#ifdef CXA_THREAD_ATEXIT_WRAPPER
1014
- dd_is_main_thread = true;
1015
- glibc__cxa_thread_atexit_impl = CXA_THREAD_ATEXIT_PHP ;
1016
- atexit (dd_clean_main_thread_locals );
1017
+ if (ddtrace_active_sapi != DATADOG_PHP_SAPI_FRANKENPHP ) {
1018
+ dd_is_main_thread = true;
1019
+ glibc__cxa_thread_atexit_impl = CXA_THREAD_ATEXIT_PHP ;
1020
+ atexit (dd_clean_main_thread_locals );
1021
+ }
1017
1022
#endif
1018
1023
1019
1024
// Reset on every minit for `apachectl graceful`.
0 commit comments