Skip to content

Commit 033303c

Browse files
committed
optimize library/framework detection for PHPs 8.0+
Take advantage of observer API and new method of storing wraprecs and don't install fcall_begin/fcall_end handlers for file execution - detect library/ framework and install wraprecs right in fcall_init!
1 parent 7e180b6 commit 033303c

File tree

3 files changed

+15
-19
lines changed

3 files changed

+15
-19
lines changed

agent/php_execute.c

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1003,7 +1003,7 @@ static void nr_php_user_instrumentation_from_file(const char* filename,
10031003
*/
10041004
#define METRIC_NAME_MAX_LEN 512
10051005

1006-
static void nr_php_execute_file(const zend_op_array* op_array,
1006+
void nr_php_execute_file(const zend_op_array* op_array,
10071007
NR_EXECUTE_PROTO TSRMLS_DC) {
10081008
const char* filename = nr_php_op_array_file_name(op_array);
10091009
size_t filename_len = nr_php_op_array_file_name_len(op_array);
@@ -1028,7 +1028,9 @@ static void nr_php_execute_file(const zend_op_array* op_array,
10281028
return;
10291029
}
10301030

1031+
#if ZEND_MODULE_API_NO < ZEND_8_0_X_API_NO
10311032
nr_php_add_user_instrumentation(TSRMLS_C);
1033+
#endif
10321034
}
10331035

10341036
/*
@@ -1926,16 +1928,7 @@ static void nr_php_instrument_func_begin(NR_EXECUTE_PROTO) {
19261928

19271929
NRTXNGLOBAL(execute_count) += 1;
19281930
txn_start_time = nr_txn_start_time(NRPRG(txn));
1929-
/*
1930-
* Handle here, but be aware the classes might not be loaded yet.
1931-
*/
1932-
if (nrunlikely(OP_ARRAY_IS_A_FILE(NR_OP_ARRAY))) {
1933-
const char* filename = nr_php_op_array_file_name(NR_OP_ARRAY);
1934-
size_t filename_len = nr_php_op_array_file_name_len(NR_OP_ARRAY);
1935-
nr_execute_handle_framework(all_frameworks, num_all_frameworks,
1936-
filename, filename_len TSRMLS_CC);
1937-
return;
1938-
}
1931+
19391932
if (NULL != NRPRG(cufa_callback) && NRPRG(check_cufa)) {
19401933
/*
19411934
* For PHP 7+, call_user_func_array() is flattened into an inline by
@@ -2021,14 +2014,6 @@ static void nr_php_instrument_func_end(NR_EXECUTE_PROTO) {
20212014
}
20222015
txn_start_time = nr_txn_start_time(NRPRG(txn));
20232016

2024-
/*
2025-
* Let's get the framework info.
2026-
*/
2027-
if (nrunlikely(OP_ARRAY_IS_A_FILE(NR_OP_ARRAY))) {
2028-
nr_php_execute_file(NR_OP_ARRAY, NR_EXECUTE_ORIG_ARGS TSRMLS_CC);
2029-
return;
2030-
}
2031-
20322017
/*
20332018
* Get the current segment and return if null.
20342019
*/

agent/php_execute.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@
2727
#define OP_ARRAY_IS_METHOD(OP, FNAME) \
2828
(0 == nr_strcmp(nr_php_op_array_function_name(OP), (FNAME)))
2929

30+
extern void nr_php_execute_file(const zend_op_array* op_array,
31+
NR_EXECUTE_PROTO TSRMLS_DC);
32+
3033
/*
3134
* Purpose: Log information about the execute data in a given execution
3235
* context - either 'execute' (zend_execute) or 'observe' (fcall_init).

agent/php_observer.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,14 @@ static zend_observer_fcall_handlers nr_php_fcall_register_handlers(
9090
nr_php_show_exec("observe", execute_data, NULL);
9191
}
9292

93+
if (OP_ARRAY_IS_A_FILE(NR_OP_ARRAY)) {
94+
/*
95+
* Let's get the framework info.
96+
*/
97+
nr_php_execute_file(NR_OP_ARRAY, execute_data, NULL TSRMLS_CC);
98+
return handlers;
99+
}
100+
93101
if (OP_ARRAY_IS_A_METHOD(&execute_data->func->op_array)) {
94102
scope_name = execute_data->func->op_array.scope->name;
95103
func_name = execute_data->func->op_array.function_name;

0 commit comments

Comments
 (0)