@@ -86,12 +86,12 @@ HashTable *main_thread_env = NULL;
8686__thread uintptr_t thread_index ;
8787__thread bool is_worker_thread = false;
8888__thread HashTable * sandboxed_env = NULL ;
89- zif_handler orig_opcache_reset ;
9089
90+ #if PHP_VERSION_ID >= 80300
9191/* Forward declaration */
9292PHP_FUNCTION (frankenphp_opcache_reset );
93+ zif_handler orig_opcache_reset ;
9394
94- #if PHP_VERSION_ID >= 80300
9595/* Try to override opcache_reset if opcache is loaded.
9696 * Safe to call multiple times - skips if already overridden in this function
9797 * table. Uses handler comparison instead of orig_opcache_reset check so that
@@ -479,12 +479,14 @@ PHP_FUNCTION(frankenphp_getenv) {
479479 }
480480} /* }}} */
481481
482+ #if PHP_VERSION_ID >= 80300
482483/* {{{ thread-safe opcache reset */
483484PHP_FUNCTION (frankenphp_opcache_reset ) {
484485 go_schedule_opcache_reset (thread_index );
485486
486487 RETVAL_TRUE ;
487488} /* }}} */
489+ #endif
488490
489491/* {{{ Fetch all HTTP request headers */
490492PHP_FUNCTION (frankenphp_request_headers ) {
@@ -768,13 +770,13 @@ static int frankenphp_startup(sapi_module_struct *sapi_module) {
768770 php_import_environment_variables = get_full_env ;
769771
770772 int result = php_module_startup (sapi_module , & frankenphp_module );
773+ #if PHP_VERSION_ID >= 80300 && PHP_VERSION_ID < 80500
771774 if (result == SUCCESS ) {
772- #if PHP_VERSION_ID >= 80300
773775 /* All extensions are now loaded. Override opcache_reset if opcache
774776 * was not yet available during our MINIT (shared extension load order). */
775777 frankenphp_override_opcache_reset ();
776- #endif
777778 }
779+ #endif
778780
779781 return result ;
780782}
@@ -1238,7 +1240,9 @@ bool frankenphp_new_php_thread(uintptr_t thread_index) {
12381240static int frankenphp_request_startup () {
12391241 frankenphp_update_request_context ();
12401242 if (php_request_startup () == SUCCESS ) {
1241- #if PHP_VERSION_ID >= 80300
1243+ #if PHP_VERSION_ID >= 80300 && PHP_VERSION_ID < 80500
1244+ /* for php 8.5+ opcache is always compiled statically, so it's already
1245+ * hooked in main request startup */
12421246 frankenphp_override_opcache_reset ();
12431247#endif
12441248 return SUCCESS ;
@@ -1440,12 +1444,20 @@ int frankenphp_execute_script_cli(char *script, int argc, char **argv,
14401444}
14411445
14421446int frankenphp_reset_opcache (void ) {
1447+ #if PHP_VERSION_ID >= 80300
14431448 zend_execute_data execute_data ;
14441449 zval retval ;
14451450 memset (& execute_data , 0 , sizeof (execute_data ));
14461451 ZVAL_UNDEF (& retval );
14471452 orig_opcache_reset (& execute_data , & retval );
14481453 zval_ptr_dtor (& retval );
1454+ #else
1455+ zend_function * opcache_reset =
1456+ zend_hash_str_find_ptr (CG (function_table ), ZEND_STRL ("opcache_reset" ));
1457+ if (opcache_reset ) {
1458+ zend_call_known_function (opcache_reset , NULL , NULL , NULL , 0 , NULL , NULL );
1459+ }
1460+ #endif
14491461 return 0 ;
14501462}
14511463
0 commit comments