|
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 | /* |
@@ -3069,6 +3099,18 @@ NR_INNER_WRAPPER(exception_common) { |
3069 | 3099 | } |
3070 | 3100 | } |
3071 | 3101 |
|
| 3102 | +#ifdef ZTS |
| 3103 | +NR_INNER_WRAPPER(frankenphp_handle_request) { |
| 3104 | + nrl_verbosedebug(NRL_INIT, "frankenphp_handle_request started"); |
| 3105 | + |
| 3106 | + nr_php_frankenphp_handle_request(INTERNAL_FUNCTION_PARAM_PASSTHRU); |
| 3107 | + |
| 3108 | + // Let frankenphp take over |
| 3109 | + nr_wrapper->oldhandler(INTERNAL_FUNCTION_PARAM_PASSTHRU); |
| 3110 | + nrl_verbosedebug(NRL_INIT, "frankenphp_handle_request done"); |
| 3111 | +} |
| 3112 | +#endif |
| 3113 | + |
3072 | 3114 | NR_OUTER_WRAPPER(mysql_select_db) |
3073 | 3115 | NR_OUTER_WRAPPER(mysql_selectdb) |
3074 | 3116 | NR_OUTER_WRAPPER(mysql_close) |
@@ -3379,6 +3421,10 @@ NR_OUTER_WRAPPER(dl) |
3379 | 3421 | NR_OUTER_WRAPPER(set_exception_handler) |
3380 | 3422 | NR_OUTER_WRAPPER(restore_exception_handler) |
3381 | 3423 |
|
| 3424 | +#ifdef ZTS |
| 3425 | +NR_OUTER_WRAPPER_DELEGATE_ALWAYS(frankenphp_handle_request) |
| 3426 | +#endif /* ZTS */ |
| 3427 | + |
3382 | 3428 | nrinternalfn_t* nr_wrapped_internal_functions = NULL; |
3383 | 3429 |
|
3384 | 3430 | static nrinternalfn_t* nr_get_wraprec(void) { |
@@ -3948,6 +3994,10 @@ void nr_php_generate_internal_wrap_records(void) { |
3948 | 3994 | exception_common, 0, 0) |
3949 | 3995 | NR_INTERNAL_WRAPREC("restore_exception_handler", restore_exception_handler, |
3950 | 3996 | exception_common, 0, 0) |
| 3997 | +#ifdef ZTS |
| 3998 | + NR_INTERNAL_WRAPREC("frankenphp_handle_request", frankenphp_handle_request, |
| 3999 | + frankenphp_handle_request, 0, 0) |
| 4000 | +#endif |
3951 | 4001 | } |
3952 | 4002 |
|
3953 | 4003 | /* |
|
0 commit comments