From ec0f1ba549841fc18549e75d3ec29390ec8f52d7 Mon Sep 17 00:00:00 2001 From: henderkes Date: Sun, 22 Nov 2026 17:09:00 +0700 Subject: [PATCH 1/7] reuse Zend Max Execution Timers across requests (Linux) --- TSRM/TSRM_atexit.h | 3 ++ TSRM/TSRM_atexit_posix.c | 5 +++ Zend/zend.c | 2 + Zend/zend_max_execution_timer.c | 80 +++++++++++++++++++++++++++++++++ Zend/zend_max_execution_timer.h | 16 +++++++ 5 files changed, 106 insertions(+) diff --git a/TSRM/TSRM_atexit.h b/TSRM/TSRM_atexit.h index ae73597e0e31..74cfcee2f3cd 100644 --- a/TSRM/TSRM_atexit.h +++ b/TSRM/TSRM_atexit.h @@ -21,6 +21,9 @@ typedef struct _tsrm_tls_entry tsrm_tls_entry; void tsrm_atexit_init(void); void tsrm_atexit_set_data(tsrm_tls_entry *thread_resources); +#if !defined(TSRM_WIN32) && !defined(__APPLE__) +bool tsrm_atexit_is_registered(void); +#endif void tsrm_atexit_disarm(void); void tsrm_free_thread_at_exit(tsrm_tls_entry *thread_resources); diff --git a/TSRM/TSRM_atexit_posix.c b/TSRM/TSRM_atexit_posix.c index cbbaafaedfe9..cfb84b8054dc 100644 --- a/TSRM/TSRM_atexit_posix.c +++ b/TSRM/TSRM_atexit_posix.c @@ -44,6 +44,11 @@ void tsrm_atexit_set_data(tsrm_tls_entry *thread_resources) pthread_setspecific(tsrm_exit_key, thread_resources); } +bool tsrm_atexit_is_registered(void) +{ + return tsrm_thread_exit_armed && pthread_getspecific(tsrm_exit_key) != NULL; +} + void tsrm_atexit_disarm(void) { if (!tsrm_thread_exit_armed) { diff --git a/Zend/zend.c b/Zend/zend.c index 560a365318de..eaf284956f71 100644 --- a/Zend/zend.c +++ b/Zend/zend.c @@ -1033,6 +1033,7 @@ void zend_startup(zend_utility_functions *utility_functions) /* {{{ */ zend_init_rsrc_list_dtors(); #ifdef ZTS + zend_max_execution_timer_cache_startup(); ts_allocate_tls_id(&compiler_globals_id, compiler_globals_tls_addr, sizeof(zend_compiler_globals), (ts_allocate_ctor) compiler_globals_ctor, (ts_allocate_dtor) compiler_globals_dtor); ts_allocate_tls_id(&executor_globals_id, executor_globals_tls_addr, sizeof(zend_executor_globals), (ts_allocate_ctor) executor_globals_ctor, (ts_allocate_dtor) executor_globals_dtor); ts_allocate_tls_id(&language_scanner_globals_id, language_scanner_globals_tls_addr, sizeof(zend_php_scanner_globals), (ts_allocate_ctor) php_scanner_globals_ctor, NULL); @@ -1214,6 +1215,7 @@ void zend_shutdown(void) /* {{{ */ zend_shutdown_strtod(); zend_attributes_shutdown(); + zend_max_execution_timer_cache_shutdown(); #ifdef ZTS GLOBAL_FUNCTION_TABLE = NULL; GLOBAL_CLASS_TABLE = NULL; diff --git a/Zend/zend_max_execution_timer.c b/Zend/zend_max_execution_timer.c index 5d0eb1219c0b..e3d8cd4665d4 100644 --- a/Zend/zend_max_execution_timer.c +++ b/Zend/zend_max_execution_timer.c @@ -29,6 +29,10 @@ #include "zend_globals.h" #include "zend_portability.h" +#if defined(ZEND_MAX_EXECUTION_TIMER_CACHE) && defined(ZTS) +# include "TSRM/TSRM_atexit.h" +#endif + #if __has_feature(memory_sanitizer) # include #endif @@ -46,6 +50,54 @@ # define ZEND_MAX_EXECUTION_TIMERS_CLOCK CLOCK_BOOTTIME # endif +#ifdef ZEND_MAX_EXECUTION_TIMER_CACHE +typedef struct { + pid_t pid; + timer_t timer; +} zend_cached_timer; + +static void timer_cache_dtor(void *ptr) +{ + zend_cached_timer *cache = ptr; + if (cache->pid == getpid()) { + timer_delete(cache->timer); + cache->pid = 0; + } +} + +# ifdef ZTS +static ts_rsrc_id timer_cache_id; +# define TIMER_CACHE (timer_cache_id ? TSRMG_BULK_STATIC(timer_cache_id, zend_cached_timer *) : NULL) +# define CAN_CACHE_TIMER() tsrm_atexit_is_registered() + +static void timer_cache_ctor(void *ptr) +{ + ((zend_cached_timer *) ptr)->pid = 0; +} + +void zend_max_execution_timer_cache_startup(void) +{ + ts_allocate_id(&timer_cache_id, sizeof(zend_cached_timer), timer_cache_ctor, timer_cache_dtor); +} + +# else +static zend_cached_timer process_timer_cache; +# define TIMER_CACHE (&process_timer_cache) +# define CAN_CACHE_TIMER() true +# endif + +void zend_max_execution_timer_cache_shutdown(void) +{ +# ifdef ZTS + if (timer_cache_id) { + ts_free_id(timer_cache_id); + } +# else + timer_cache_dtor(&process_timer_cache); +# endif +} +#endif + ZEND_API void zend_max_execution_timer_init(void) /* {{{ */ { pid_t pid = getpid(); @@ -54,6 +106,20 @@ ZEND_API void zend_max_execution_timer_init(void) /* {{{ */ return; } +#ifdef ZEND_MAX_EXECUTION_TIMER_CACHE + zend_cached_timer *cache = TIMER_CACHE; + if (cache && cache->pid == pid) { + EG(max_execution_timer_timer) = cache->timer; + EG(pid) = pid; + cache->pid = 0; +# ifdef MAX_EXECUTION_TIMERS_DEBUG + fprintf(stderr, "Timer %#jx reused on thread %d\n", (uintmax_t) EG(max_execution_timer_timer), (pid_t) syscall(SYS_gettid)); +# endif + sigaction(SIGRTMIN, NULL, &EG(oldact)); + return; + } +#endif + struct sigevent sev; sev.sigev_notify = SIGEV_THREAD_ID; sev.sigev_value.sival_ptr = &EG(max_execution_timer_timer); @@ -120,6 +186,20 @@ void zend_max_execution_timer_shutdown(void) /* {{{ */ return; } +#ifdef ZEND_MAX_EXECUTION_TIMER_CACHE + static const struct itimerspec disarmed = {0}; + zend_cached_timer *cache = TIMER_CACHE; + if (cache && CAN_CACHE_TIMER() + && timer_settime(EG(max_execution_timer_timer), 0, &disarmed, NULL) == 0) { + *cache = (zend_cached_timer) {EG(pid), EG(max_execution_timer_timer)}; + EG(pid) = 0; +# ifdef MAX_EXECUTION_TIMERS_DEBUG + fprintf(stderr, "Timer %#jx disarmed and cached on thread %d\n", (uintmax_t) cache->timer, (pid_t) syscall(SYS_gettid)); +# endif + return; + } +#endif + EG(pid) = 0; timer_t timer = EG(max_execution_timer_timer); diff --git a/Zend/zend_max_execution_timer.h b/Zend/zend_max_execution_timer.h index 3839ea4cf676..ddb1e0ca44a0 100644 --- a/Zend/zend_max_execution_timer.h +++ b/Zend/zend_max_execution_timer.h @@ -19,6 +19,11 @@ #include "zend_long.h" +/* Linux reuses each thread's timer across requests instead of recreating it. */ +# ifdef __linux__ +# define ZEND_MAX_EXECUTION_TIMER_CACHE +# endif + BEGIN_EXTERN_C() /* Must be called after calls to fork() */ ZEND_API void zend_max_execution_timer_init(void); @@ -33,4 +38,15 @@ void zend_max_execution_timer_shutdown(void); #define zend_max_execution_timer_shutdown() # endif + +# ifdef ZEND_MAX_EXECUTION_TIMER_CACHE +# ifdef ZTS +void zend_max_execution_timer_cache_startup(void); +# endif +void zend_max_execution_timer_cache_shutdown(void); +# else +# define zend_max_execution_timer_cache_startup() +# define zend_max_execution_timer_cache_shutdown() +# endif + #endif From 8b3fbd717040c581c2eddecbf9aff57d376d6e9b Mon Sep 17 00:00:00 2001 From: henderkes Date: Mon, 23 Nov 2026 18:34:14 +0700 Subject: [PATCH 2/7] fix recursive forwarding of SIGRTMIN signals: make sure we don't accidentally save our own handler --- Zend/zend_execute_API.c | 2 +- Zend/zend_max_execution_timer.c | 15 +++++++++++++-- Zend/zend_max_execution_timer.h | 2 ++ 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/Zend/zend_execute_API.c b/Zend/zend_execute_API.c index 94273a4bc59f..f8ffd541d41c 100644 --- a/Zend/zend_execute_API.c +++ b/Zend/zend_execute_API.c @@ -1520,7 +1520,7 @@ ZEND_NORETURN ZEND_API void ZEND_FASTCALL zend_timeout(void) /* {{{ */ #ifndef ZEND_WIN32 # ifdef ZEND_MAX_EXECUTION_TIMERS -static void zend_timeout_handler(int dummy, siginfo_t *si, void *uc) /* {{{ */ +void zend_timeout_handler(int dummy, siginfo_t *si, void *uc) /* {{{ */ { #ifdef ZTS if (!tsrm_is_managed_thread()) { diff --git a/Zend/zend_max_execution_timer.c b/Zend/zend_max_execution_timer.c index e3d8cd4665d4..320801a3ec20 100644 --- a/Zend/zend_max_execution_timer.c +++ b/Zend/zend_max_execution_timer.c @@ -98,6 +98,18 @@ void zend_max_execution_timer_cache_shutdown(void) } #endif +/* Remember the SIGRTMIN handler that zend_timeout_handler() forwards foreign + * signals to. After a request installs zend_timeout_handler(), the current + * handler is ours, and saving it would recursively forward forever. */ +static void zend_max_execution_timer_save_oldact(void) +{ + struct sigaction act; + + if (sigaction(SIGRTMIN, NULL, &act) == 0 && act.sa_sigaction != zend_timeout_handler) { + EG(oldact) = act; + } +} + ZEND_API void zend_max_execution_timer_init(void) /* {{{ */ { pid_t pid = getpid(); @@ -115,7 +127,6 @@ ZEND_API void zend_max_execution_timer_init(void) /* {{{ */ # ifdef MAX_EXECUTION_TIMERS_DEBUG fprintf(stderr, "Timer %#jx reused on thread %d\n", (uintmax_t) EG(max_execution_timer_timer), (pid_t) syscall(SYS_gettid)); # endif - sigaction(SIGRTMIN, NULL, &EG(oldact)); return; } #endif @@ -147,7 +158,7 @@ ZEND_API void zend_max_execution_timer_init(void) /* {{{ */ fprintf(stderr, "Timer %#jx created on thread %d\n", (uintmax_t) EG(max_execution_timer_timer), sev.sigev_notify_thread_id); # endif - sigaction(sev.sigev_signo, NULL, &EG(oldact)); + zend_max_execution_timer_save_oldact(); } /* }}} */ diff --git a/Zend/zend_max_execution_timer.h b/Zend/zend_max_execution_timer.h index ddb1e0ca44a0..79396fb5a498 100644 --- a/Zend/zend_max_execution_timer.h +++ b/Zend/zend_max_execution_timer.h @@ -17,6 +17,7 @@ # ifdef ZEND_MAX_EXECUTION_TIMERS +#include #include "zend_long.h" /* Linux reuses each thread's timer across requests instead of recreating it. */ @@ -30,6 +31,7 @@ ZEND_API void zend_max_execution_timer_init(void); END_EXTERN_C() void zend_max_execution_timer_settime(zend_long seconds); void zend_max_execution_timer_shutdown(void); +void zend_timeout_handler(int dummy, siginfo_t *si, void *uc); # else From d2cf0af70d1e6a84f78de88ed85931d7631e66c8 Mon Sep 17 00:00:00 2001 From: henderkes Date: Mon, 23 Nov 2026 18:44:39 +0700 Subject: [PATCH 3/7] add test for max execution timer reuse --- sapi/cli/tests/max_execution_timer_reuse.phpt | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 sapi/cli/tests/max_execution_timer_reuse.phpt diff --git a/sapi/cli/tests/max_execution_timer_reuse.phpt b/sapi/cli/tests/max_execution_timer_reuse.phpt new file mode 100644 index 000000000000..846b91b599a2 --- /dev/null +++ b/sapi/cli/tests/max_execution_timer_reuse.phpt @@ -0,0 +1,45 @@ +--TEST-- +Zend max execution timers keep firing when reused across requests on one thread +--INI-- +allow_url_fopen=1 +--SKIPIF-- + enabled')) { + die("skip Zend max execution timers are disabled"); +} +?> +--FILE-- + ['ignore_errors' => true, 'timeout' => 10]]); +foreach (['busy', 'idle', 'busy'] as $request) { + $query = $request === 'busy' ? '?busy=1' : ''; + $body = @file_get_contents("http://" . PHP_CLI_SERVER_ADDRESS . "/$query", false, $context); + if ($body === false) { + echo "$request: no response\n"; + } elseif (preg_match('/Maximum execution time of 1 second exceeded/', $body)) { + echo "$request: timed out\n"; + } else { + echo "$request: ", trim($body), "\n"; + } +} +?> +--EXPECT-- +busy: timed out +idle: ok +busy: timed out From 1ca949297a9cf237823ef191367e5dd0800ea581 Mon Sep 17 00:00:00 2001 From: henderkes Date: Mon, 23 Nov 2026 18:51:12 +0700 Subject: [PATCH 4/7] create NEWS entry --- NEWS | 2 ++ 1 file changed, 2 insertions(+) diff --git a/NEWS b/NEWS index eaeb9894e2b2..78e772d44b7c 100644 --- a/NEWS +++ b/NEWS @@ -11,6 +11,8 @@ PHP NEWS . Improved performance of integer to string conversion, used by string casts, echo, implode(), json_encode(), serialize() and other places, by emitting two digits per step. (Alexander Danilov) + . Zend max execution timers are now reused across requests on Linux + instead of being recreated for every request. (henderkes) - Curl: . Negative values for CURLOPT_POSTREDIR are now rejected, causing From 4105225e74bd3df6deeffdc8f1f0b88aaf073cc3 Mon Sep 17 00:00:00 2001 From: henderkes Date: Tue, 24 Nov 2026 08:45:59 +0700 Subject: [PATCH 5/7] Keep execution timers owned by the cache until deletion --- Zend/zend.c | 3 +-- Zend/zend_API.c | 1 + Zend/zend_max_execution_timer.c | 16 ++++++++++++---- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/Zend/zend.c b/Zend/zend.c index eaf284956f71..744c593d9de4 100644 --- a/Zend/zend.c +++ b/Zend/zend.c @@ -1033,7 +1033,6 @@ void zend_startup(zend_utility_functions *utility_functions) /* {{{ */ zend_init_rsrc_list_dtors(); #ifdef ZTS - zend_max_execution_timer_cache_startup(); ts_allocate_tls_id(&compiler_globals_id, compiler_globals_tls_addr, sizeof(zend_compiler_globals), (ts_allocate_ctor) compiler_globals_ctor, (ts_allocate_dtor) compiler_globals_dtor); ts_allocate_tls_id(&executor_globals_id, executor_globals_tls_addr, sizeof(zend_executor_globals), (ts_allocate_ctor) executor_globals_ctor, (ts_allocate_dtor) executor_globals_dtor); ts_allocate_tls_id(&language_scanner_globals_id, language_scanner_globals_tls_addr, sizeof(zend_php_scanner_globals), (ts_allocate_ctor) php_scanner_globals_ctor, NULL); @@ -1091,6 +1090,7 @@ void zend_startup(zend_utility_functions *utility_functions) /* {{{ */ zend_optimizer_startup(); #ifdef ZTS + zend_max_execution_timer_cache_startup(); tsrm_set_new_thread_end_handler(zend_new_thread_end_handler); tsrm_set_thread_free_handler(zend_thread_free_handler); tsrm_set_shutdown_handler(zend_interned_strings_dtor); @@ -1215,7 +1215,6 @@ void zend_shutdown(void) /* {{{ */ zend_shutdown_strtod(); zend_attributes_shutdown(); - zend_max_execution_timer_cache_shutdown(); #ifdef ZTS GLOBAL_FUNCTION_TABLE = NULL; GLOBAL_CLASS_TABLE = NULL; diff --git a/Zend/zend_API.c b/Zend/zend_API.c index c19e9d64e266..568bff81d604 100644 --- a/Zend/zend_API.c +++ b/Zend/zend_API.c @@ -2595,6 +2595,7 @@ ZEND_API void zend_destroy_modules(void) /* {{{ */ free(module_request_startup_handlers); module_request_startup_handlers = NULL; zend_hash_graceful_reverse_destroy(&module_registry); + zend_max_execution_timer_cache_shutdown(); } /* }}} */ diff --git a/Zend/zend_max_execution_timer.c b/Zend/zend_max_execution_timer.c index 320801a3ec20..6b0dd147f0bb 100644 --- a/Zend/zend_max_execution_timer.c +++ b/Zend/zend_max_execution_timer.c @@ -51,6 +51,7 @@ # endif #ifdef ZEND_MAX_EXECUTION_TIMER_CACHE +/* Owns the timer from creation until deletion, including during a request. */ typedef struct { pid_t pid; timer_t timer; @@ -61,8 +62,8 @@ static void timer_cache_dtor(void *ptr) zend_cached_timer *cache = ptr; if (cache->pid == getpid()) { timer_delete(cache->timer); - cache->pid = 0; } + cache->pid = 0; } # ifdef ZTS @@ -91,6 +92,7 @@ void zend_max_execution_timer_cache_shutdown(void) # ifdef ZTS if (timer_cache_id) { ts_free_id(timer_cache_id); + timer_cache_id = 0; } # else timer_cache_dtor(&process_timer_cache); @@ -123,7 +125,6 @@ ZEND_API void zend_max_execution_timer_init(void) /* {{{ */ if (cache && cache->pid == pid) { EG(max_execution_timer_timer) = cache->timer; EG(pid) = pid; - cache->pid = 0; # ifdef MAX_EXECUTION_TIMERS_DEBUG fprintf(stderr, "Timer %#jx reused on thread %d\n", (uintmax_t) EG(max_execution_timer_timer), (pid_t) syscall(SYS_gettid)); # endif @@ -153,6 +154,11 @@ ZEND_API void zend_max_execution_timer_init(void) /* {{{ */ } EG(pid) = pid; +#ifdef ZEND_MAX_EXECUTION_TIMER_CACHE + if (cache) { + *cache = (zend_cached_timer) {pid, EG(max_execution_timer_timer)}; + } +#endif # ifdef MAX_EXECUTION_TIMERS_DEBUG fprintf(stderr, "Timer %#jx created on thread %d\n", (uintmax_t) EG(max_execution_timer_timer), sev.sigev_notify_thread_id); @@ -200,15 +206,17 @@ void zend_max_execution_timer_shutdown(void) /* {{{ */ #ifdef ZEND_MAX_EXECUTION_TIMER_CACHE static const struct itimerspec disarmed = {0}; zend_cached_timer *cache = TIMER_CACHE; - if (cache && CAN_CACHE_TIMER() + if (cache && cache->pid == EG(pid) && CAN_CACHE_TIMER() && timer_settime(EG(max_execution_timer_timer), 0, &disarmed, NULL) == 0) { - *cache = (zend_cached_timer) {EG(pid), EG(max_execution_timer_timer)}; EG(pid) = 0; # ifdef MAX_EXECUTION_TIMERS_DEBUG fprintf(stderr, "Timer %#jx disarmed and cached on thread %d\n", (uintmax_t) cache->timer, (pid_t) syscall(SYS_gettid)); # endif return; } + if (cache) { + cache->pid = 0; + } #endif EG(pid) = 0; From 03f0270cbdd95e864429e6d0d3541b45c00fb820 Mon Sep 17 00:00:00 2001 From: henderkes Date: Tue, 24 Nov 2026 08:46:20 +0700 Subject: [PATCH 6/7] preserve the hosts process-wide SIGTRMIN handler remember it once for all threads, so a host signal still reaches its handler if it lands on a different PHP thread --- Zend/zend.c | 1 - Zend/zend_execute_API.c | 29 +++++++++++++++++++++++------ Zend/zend_globals.h | 1 - Zend/zend_max_execution_timer.c | 14 -------------- Zend/zend_max_execution_timer.h | 2 -- 5 files changed, 23 insertions(+), 24 deletions(-) diff --git a/Zend/zend.c b/Zend/zend.c index 744c593d9de4..49fd16a5b222 100644 --- a/Zend/zend.c +++ b/Zend/zend.c @@ -851,7 +851,6 @@ static void executor_globals_ctor(zend_executor_globals *executor_globals) /* {{ #endif #ifdef ZEND_MAX_EXECUTION_TIMERS executor_globals->pid = 0; - executor_globals->oldact = (struct sigaction){0}; #endif memset(executor_globals->strtod_state.freelist, 0, sizeof(executor_globals->strtod_state.freelist)); diff --git a/Zend/zend_execute_API.c b/Zend/zend_execute_API.c index f8ffd541d41c..4317ba0de1d7 100644 --- a/Zend/zend_execute_API.c +++ b/Zend/zend_execute_API.c @@ -1520,7 +1520,11 @@ ZEND_NORETURN ZEND_API void ZEND_FASTCALL zend_timeout(void) /* {{{ */ #ifndef ZEND_WIN32 # ifdef ZEND_MAX_EXECUTION_TIMERS -void zend_timeout_handler(int dummy, siginfo_t *si, void *uc) /* {{{ */ +/* The handler we displaced is process-wide. A null sigaction selects the one-argument handler. */ +static _Atomic(void (*)(int, siginfo_t *, void *)) previous_sigaction; +static _Atomic(void (*)(int)) previous_handler; + +static void zend_timeout_handler(int dummy, siginfo_t *si, void *uc) /* {{{ */ { #ifdef ZTS if (!tsrm_is_managed_thread()) { @@ -1535,12 +1539,16 @@ void zend_timeout_handler(int dummy, siginfo_t *si, void *uc) /* {{{ */ fprintf(stderr, "Executing previous handler (if set) for unexpected signal SIGRTMIN received on thread %d\n", (pid_t) syscall(SYS_gettid)); #endif - if (EG(oldact).sa_sigaction) { - EG(oldact).sa_sigaction(dummy, si, uc); + void (*action)(int, siginfo_t *, void *) = atomic_load(&previous_sigaction); + if (action) { + action(dummy, si, uc); return; } - if (EG(oldact).sa_handler) EG(oldact).sa_handler(dummy); + void (*handler)(int) = atomic_load(&previous_handler); + if (handler != SIG_IGN && handler != SIG_DFL) { + handler(dummy); + } return; } @@ -1658,12 +1666,21 @@ static void zend_set_timeout_ex(zend_long seconds, bool reset_signals) /* {{{ */ if (reset_signals) { sigset_t sigset; - struct sigaction act; + struct sigaction act, old; act.sa_sigaction = zend_timeout_handler; sigemptyset(&act.sa_mask); act.sa_flags = SA_ONSTACK | SA_SIGINFO; - sigaction(SIGRTMIN, &act, NULL); + if (sigaction(SIGRTMIN, NULL, &old) == 0 + && !((old.sa_flags & SA_SIGINFO) && old.sa_sigaction == zend_timeout_handler)) { + if ((old.sa_flags & SA_SIGINFO) && old.sa_handler != SIG_DFL && old.sa_handler != SIG_IGN) { + atomic_store(&previous_sigaction, old.sa_sigaction); + } else { + atomic_store(&previous_handler, old.sa_handler); + atomic_store(&previous_sigaction, NULL); + } + sigaction(SIGRTMIN, &act, NULL); + } sigemptyset(&sigset); sigaddset(&sigset, SIGRTMIN); sigprocmask(SIG_UNBLOCK, &sigset, NULL); diff --git a/Zend/zend_globals.h b/Zend/zend_globals.h index bf93bf0013a9..17882a3bc9b8 100644 --- a/Zend/zend_globals.h +++ b/Zend/zend_globals.h @@ -327,7 +327,6 @@ struct _zend_executor_globals { #ifdef ZEND_MAX_EXECUTION_TIMERS timer_t max_execution_timer_timer; pid_t pid; - struct sigaction oldact; #endif zend_strtod_state strtod_state; diff --git a/Zend/zend_max_execution_timer.c b/Zend/zend_max_execution_timer.c index 6b0dd147f0bb..7ac1e40637eb 100644 --- a/Zend/zend_max_execution_timer.c +++ b/Zend/zend_max_execution_timer.c @@ -100,18 +100,6 @@ void zend_max_execution_timer_cache_shutdown(void) } #endif -/* Remember the SIGRTMIN handler that zend_timeout_handler() forwards foreign - * signals to. After a request installs zend_timeout_handler(), the current - * handler is ours, and saving it would recursively forward forever. */ -static void zend_max_execution_timer_save_oldact(void) -{ - struct sigaction act; - - if (sigaction(SIGRTMIN, NULL, &act) == 0 && act.sa_sigaction != zend_timeout_handler) { - EG(oldact) = act; - } -} - ZEND_API void zend_max_execution_timer_init(void) /* {{{ */ { pid_t pid = getpid(); @@ -163,8 +151,6 @@ ZEND_API void zend_max_execution_timer_init(void) /* {{{ */ # ifdef MAX_EXECUTION_TIMERS_DEBUG fprintf(stderr, "Timer %#jx created on thread %d\n", (uintmax_t) EG(max_execution_timer_timer), sev.sigev_notify_thread_id); # endif - - zend_max_execution_timer_save_oldact(); } /* }}} */ diff --git a/Zend/zend_max_execution_timer.h b/Zend/zend_max_execution_timer.h index 79396fb5a498..ddb1e0ca44a0 100644 --- a/Zend/zend_max_execution_timer.h +++ b/Zend/zend_max_execution_timer.h @@ -17,7 +17,6 @@ # ifdef ZEND_MAX_EXECUTION_TIMERS -#include #include "zend_long.h" /* Linux reuses each thread's timer across requests instead of recreating it. */ @@ -31,7 +30,6 @@ ZEND_API void zend_max_execution_timer_init(void); END_EXTERN_C() void zend_max_execution_timer_settime(zend_long seconds); void zend_max_execution_timer_shutdown(void); -void zend_timeout_handler(int dummy, siginfo_t *si, void *uc); # else From f44c1eb6bf17347b72c4046382732ff762119094 Mon Sep 17 00:00:00 2001 From: henderkes Date: Wed, 25 Nov 2026 15:04:11 +0700 Subject: [PATCH 7/7] test in single process --- sapi/cli/tests/max_execution_timer_reuse.phpt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/sapi/cli/tests/max_execution_timer_reuse.phpt b/sapi/cli/tests/max_execution_timer_reuse.phpt index 846b91b599a2..830c9a2862ed 100644 --- a/sapi/cli/tests/max_execution_timer_reuse.phpt +++ b/sapi/cli/tests/max_execution_timer_reuse.phpt @@ -1,5 +1,7 @@ --TEST-- Zend max execution timers keep firing when reused across requests on one thread +--ENV-- +PHP_CLI_SERVER_WORKERS= --INI-- allow_url_fopen=1 --SKIPIF--