Skip to content

Commit f5d0240

Browse files
committed
only run frankenphp_register_atfork once, actually showed up in pgo data
1 parent a4386ad commit f5d0240

2 files changed

Lines changed: 7 additions & 1 deletion

File tree

caddy/frankenphp/default.pgo

282 KB
Binary file not shown.

frankenphp.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,10 @@ __thread HashTable *sandboxed_env = NULL;
9090
#ifndef PHP_WIN32
9191
static bool is_forked_child = false;
9292
static void frankenphp_fork_child(void) { is_forked_child = true; }
93+
94+
static void frankenphp_register_atfork(void) {
95+
pthread_atfork(NULL, NULL, frankenphp_fork_child);
96+
}
9397
#endif
9498

9599
void frankenphp_update_local_thread_context(bool is_worker) {
@@ -711,7 +715,9 @@ PHP_FUNCTION(frankenphp_log) {
711715
PHP_MINIT_FUNCTION(frankenphp) {
712716
register_frankenphp_symbols(module_number);
713717
#ifndef PHP_WIN32
714-
pthread_atfork(NULL, NULL, frankenphp_fork_child);
718+
/* MINIT runs once per ZTS thread — guard the atfork registration */
719+
static pthread_once_t atfork_once = PTHREAD_ONCE_INIT;
720+
pthread_once(&atfork_once, frankenphp_register_atfork);
715721
#endif
716722

717723
zend_function *func;

0 commit comments

Comments
 (0)