|
12 | 12 | #include "php_explain.h" |
13 | 13 | #include "php_explain_mysqli.h" |
14 | 14 | #include "php_file_get_contents.h" |
| 15 | +#include "php_frankenphp.h" |
15 | 16 | #include "php_globals.h" |
16 | 17 | #include "php_hash.h" |
17 | 18 | #include "php_httprequest_send.h" |
@@ -113,6 +114,28 @@ static void nr_php_instrument_delegate(nrinternalfn_t* wraprec, |
113 | 114 | (wraprec->inner_wrapper)(INTERNAL_FUNCTION_PARAM_PASSTHRU, wraprec); |
114 | 115 | } |
115 | 116 |
|
| 117 | +#if ZEND_MODULE_API_NO >= ZEND_8_0_X_API_NO |
| 118 | +/* |
| 119 | + * This delegate is used for the wrappers, which need to execute its inner |
| 120 | + * wrapper on every call, even when not recording. This can be used for starting |
| 121 | + * the transaction and thus needs to execute its inner wrapper to start |
| 122 | + * recording. |
| 123 | + */ |
| 124 | +static void nr_php_instrument_delegate_always(nrinternalfn_t* wraprec, |
| 125 | + INTERNAL_FUNCTION_PARAMETERS) { |
| 126 | + if ((NULL == wraprec) || (NULL == wraprec->oldhandler) |
| 127 | + || (NULL == wraprec->inner_wrapper)) { |
| 128 | + /* |
| 129 | + * This conditional should never happen: The wraprec and its fields |
| 130 | + * should be properly populated during construction. Perhaps this should |
| 131 | + * be changed into some sort of assertion. |
| 132 | + */ |
| 133 | + return; |
| 134 | + } |
| 135 | + (wraprec->inner_wrapper)(INTERNAL_FUNCTION_PARAM_PASSTHRU, wraprec); |
| 136 | +} |
| 137 | +#endif |
| 138 | + |
116 | 139 | #define NR_OUTER_WRAPPER_NAME(RAW) _nr_outer_wrapper_function_##RAW |
117 | 140 | #define NR_OUTER_GLOBAL_NAME(RAW) _nr_outer_wrapper_global_##RAW |
118 | 141 | #define NR_INNER_WRAPPER_NAME(RAW) _nr_inner_wrapper_function_##RAW |
@@ -142,6 +165,13 @@ static void nr_php_instrument_delegate(nrinternalfn_t* wraprec, |
142 | 165 | nr_php_instrument_delegate(NR_OUTER_GLOBAL_NAME(RAW), \ |
143 | 166 | INTERNAL_FUNCTION_PARAM_PASSTHRU); \ |
144 | 167 | } |
| 168 | +#define NR_OUTER_WRAPPER_DELEGATE_ALWAYS(RAW) \ |
| 169 | + static nrinternalfn_t* NR_OUTER_GLOBAL_NAME(RAW) = NULL; \ |
| 170 | + static void ZEND_FASTCALL NR_OUTER_WRAPPER_NAME(RAW)( \ |
| 171 | + INTERNAL_FUNCTION_PARAMETERS) { \ |
| 172 | + nr_php_instrument_delegate_always(NR_OUTER_GLOBAL_NAME(RAW), \ |
| 173 | + INTERNAL_FUNCTION_PARAM_PASSTHRU); \ |
| 174 | + } |
145 | 175 | #endif /* PHP < 7.3 */ |
146 | 176 |
|
147 | 177 | /* |
@@ -3089,6 +3119,18 @@ NR_INNER_WRAPPER(exception_common) { |
3089 | 3119 | } |
3090 | 3120 | } |
3091 | 3121 |
|
| 3122 | +#ifdef ZTS |
| 3123 | +NR_INNER_WRAPPER(frankenphp_handle_request) { |
| 3124 | + nrl_verbosedebug(NRL_INIT, "frankenphp_handle_request started"); |
| 3125 | + |
| 3126 | + nr_php_frankenphp_handle_request(INTERNAL_FUNCTION_PARAM_PASSTHRU); |
| 3127 | + |
| 3128 | + // Let frankenphp take over |
| 3129 | + nr_wrapper->oldhandler(INTERNAL_FUNCTION_PARAM_PASSTHRU); |
| 3130 | + nrl_verbosedebug(NRL_INIT, "frankenphp_handle_request done"); |
| 3131 | +} |
| 3132 | +#endif |
| 3133 | + |
3092 | 3134 | NR_OUTER_WRAPPER(mysql_select_db) |
3093 | 3135 | NR_OUTER_WRAPPER(mysql_selectdb) |
3094 | 3136 | NR_OUTER_WRAPPER(mysql_close) |
@@ -3538,6 +3580,10 @@ NR_OUTER_WRAPPER(dl) |
3538 | 3580 | NR_OUTER_WRAPPER(set_exception_handler) |
3539 | 3581 | NR_OUTER_WRAPPER(restore_exception_handler) |
3540 | 3582 |
|
| 3583 | +#ifdef ZTS |
| 3584 | +NR_OUTER_WRAPPER_DELEGATE_ALWAYS(frankenphp_handle_request) |
| 3585 | +#endif /* ZTS */ |
| 3586 | + |
3541 | 3587 | nrinternalfn_t* nr_wrapped_internal_functions = NULL; |
3542 | 3588 |
|
3543 | 3589 | static nrinternalfn_t* nr_get_wraprec(void) { |
@@ -4391,6 +4437,10 @@ void nr_php_generate_internal_wrap_records(void) { |
4391 | 4437 | exception_common, 0, 0) |
4392 | 4438 | NR_INTERNAL_WRAPREC("restore_exception_handler", restore_exception_handler, |
4393 | 4439 | exception_common, 0, 0) |
| 4440 | +#ifdef ZTS |
| 4441 | + NR_INTERNAL_WRAPREC("frankenphp_handle_request", frankenphp_handle_request, |
| 4442 | + frankenphp_handle_request, 0, 0) |
| 4443 | +#endif |
4394 | 4444 | } |
4395 | 4445 |
|
4396 | 4446 | /* |
|
0 commit comments