refactor: call opcache_reset PHP function directly (#1401)

* Call opcache_reset PHP function directly

* prevent warning

* cleanup

* remove frankenphp_execute_php_function

* cs

---------

Co-authored-by: Kévin Dunglas <kevin@dunglas.fr>
This commit is contained in:
Gina Peter Banyard
2025-03-24 10:29:13 +00:00
committed by GitHub
parent f36bd51163
commit 3701516e5e
3 changed files with 5 additions and 31 deletions

View File

@@ -1161,30 +1161,13 @@ int frankenphp_execute_script_cli(char *script, int argc, char **argv) {
return (intptr_t)exit_status;
}
int frankenphp_execute_php_function(const char *php_function) {
zval retval = {0};
zend_fcall_info fci = {0};
zend_fcall_info_cache fci_cache = {0};
zend_string *func_name =
zend_string_init(php_function, strlen(php_function), 0);
ZVAL_STR(&fci.function_name, func_name);
fci.size = sizeof fci;
fci.retval = &retval;
int success = 0;
zend_try { success = zend_call_function(&fci, &fci_cache) == SUCCESS; }
zend_end_try();
zend_string_release(func_name);
return success;
}
int frankenphp_reset_opcache(void) {
if (zend_hash_str_exists(CG(function_table), "opcache_reset",
sizeof("opcache_reset") - 1)) {
return frankenphp_execute_php_function("opcache_reset");
zend_function *opcache_reset =
zend_hash_str_find_ptr(CG(function_table), ZEND_STRL("opcache_reset"));
if (opcache_reset) {
zend_call_known_function(opcache_reset, NULL, NULL, NULL, 0, NULL, NULL);
}
return 0;
}

View File

@@ -653,13 +653,6 @@ func freeArgs(argv []*C.char) {
}
}
func executePHPFunction(functionName string) bool {
cFunctionName := C.CString(functionName)
defer C.free(unsafe.Pointer(cFunctionName))
return C.frankenphp_execute_php_function(cFunctionName) == 1
}
func timeoutChan(timeout time.Duration) <-chan time.Time {
if timeout == 0 {
return nil

View File

@@ -63,8 +63,6 @@ int frankenphp_execute_script(char *file_name);
int frankenphp_execute_script_cli(char *script, int argc, char **argv);
int frankenphp_execute_php_function(const char *php_function);
void frankenphp_register_variables_from_request_info(
zval *track_vars_array, zend_string *content_type,
zend_string *path_translated, zend_string *query_string,