From 3293fafa2724044bbd17e1dcba93bb0bc020cd32 Mon Sep 17 00:00:00 2001 From: Florian Engelhardt Date: Tue, 24 Sep 2024 16:24:01 +0200 Subject: [PATCH] Add OPcache restart hook (#15590) This hook will allow observing extensions to observe the actual OPcache restart. --- Zend/zend.c | 1 + Zend/zend.h | 2 ++ ext/opcache/ZendAccelerator.c | 5 +++++ ext/opcache/ZendAccelerator.h | 2 +- 4 files changed, 9 insertions(+), 1 deletion(-) diff --git a/Zend/zend.c b/Zend/zend.c index 8f46b6f4257..b4fd4fd269c 100644 --- a/Zend/zend.c +++ b/Zend/zend.c @@ -94,6 +94,7 @@ ZEND_API char *(*zend_getenv)(const char *name, size_t name_len); ZEND_API zend_string *(*zend_resolve_path)(zend_string *filename); ZEND_API zend_result (*zend_post_startup_cb)(void) = NULL; ZEND_API void (*zend_post_shutdown_cb)(void) = NULL; +ZEND_API void (*zend_accel_schedule_restart_hook)(int reason) = NULL; ZEND_ATTRIBUTE_NONNULL ZEND_API zend_result (*zend_random_bytes)(void *bytes, size_t size, char *errstr, size_t errstr_size) = NULL; ZEND_ATTRIBUTE_NONNULL ZEND_API void (*zend_random_bytes_insecure)(zend_random_bytes_insecure_state *state, void *bytes, size_t size) = NULL; diff --git a/Zend/zend.h b/Zend/zend.h index 1506b868e16..b7dc8ae2f67 100644 --- a/Zend/zend.h +++ b/Zend/zend.h @@ -377,6 +377,8 @@ extern ZEND_ATTRIBUTE_NONNULL ZEND_API void (*zend_random_bytes_insecure)( extern ZEND_API zend_result (*zend_post_startup_cb)(void); extern ZEND_API void (*zend_post_shutdown_cb)(void); +extern ZEND_API void (*zend_accel_schedule_restart_hook)(int reason); + ZEND_API ZEND_COLD void zend_error(int type, const char *format, ...) ZEND_ATTRIBUTE_FORMAT(printf, 2, 3); ZEND_API ZEND_COLD ZEND_NORETURN void zend_error_noreturn(int type, const char *format, ...) ZEND_ATTRIBUTE_FORMAT(printf, 2, 3); ZEND_API ZEND_COLD ZEND_NORETURN void zend_error_noreturn_unchecked(int type, const char *format, ...); diff --git a/ext/opcache/ZendAccelerator.c b/ext/opcache/ZendAccelerator.c index 10ed5e1333d..3e8bdea9c7a 100644 --- a/ext/opcache/ZendAccelerator.c +++ b/ext/opcache/ZendAccelerator.c @@ -3431,6 +3431,11 @@ void zend_accel_schedule_restart(zend_accel_restart_reason reason) /* don't schedule twice */ return; } + + if (UNEXPECTED(zend_accel_schedule_restart_hook)) { + zend_accel_schedule_restart_hook(reason); + } + zend_accel_error(ACCEL_LOG_DEBUG, "Restart Scheduled! Reason: %s", zend_accel_restart_reason_text[reason]); diff --git a/ext/opcache/ZendAccelerator.h b/ext/opcache/ZendAccelerator.h index 682677441e4..162892bf2c2 100644 --- a/ext/opcache/ZendAccelerator.h +++ b/ext/opcache/ZendAccelerator.h @@ -311,7 +311,7 @@ extern const char *zps_api_failure_reason; BEGIN_EXTERN_C() void accel_shutdown(void); -zend_result accel_activate(INIT_FUNC_ARGS); +zend_result accel_activate(INIT_FUNC_ARGS); zend_result accel_post_deactivate(void); void zend_accel_schedule_restart(zend_accel_restart_reason reason); void zend_accel_schedule_restart_if_necessary(zend_accel_restart_reason reason);