diff --git a/frankenphp.c b/frankenphp.c index 7f396989a..8dccd9af6 100644 --- a/frankenphp.c +++ b/frankenphp.c @@ -87,6 +87,11 @@ __thread uintptr_t thread_index; __thread bool is_worker_thread = false; __thread HashTable *sandboxed_env = NULL; +#ifndef PHP_WIN32 +static bool is_forked_child = false; +static void frankenphp_fork_child(void) { is_forked_child = true; } +#endif + void frankenphp_update_local_thread_context(bool is_worker) { is_worker_thread = is_worker; @@ -602,6 +607,11 @@ PHP_FUNCTION(frankenphp_handle_request) { } frankenphp_worker_request_shutdown(); +#ifndef PHP_WIN32 + if (is_forked_child) { + _exit(0); + } +#endif go_frankenphp_finish_worker_request(thread_index, callback_ret); if (result.r1 != NULL) { zval_ptr_dtor(result.r1); @@ -699,6 +709,9 @@ PHP_FUNCTION(frankenphp_log) { PHP_MINIT_FUNCTION(frankenphp) { register_frankenphp_symbols(module_number); +#ifndef PHP_WIN32 + pthread_atfork(NULL, NULL, frankenphp_fork_child); +#endif zend_function *func; @@ -1098,6 +1111,11 @@ static void *php_thread(void *arg) { /* shutdown the request, potential bailout to zend_catch */ php_request_shutdown((void *)0); frankenphp_free_request_context(); +#ifndef PHP_WIN32 + if (is_forked_child) { + _exit(EG(exit_status)); + } +#endif go_frankenphp_after_script_execution(thread_index, EG(exit_status)); } } @@ -1121,6 +1139,11 @@ static void *php_thread(void *arg) { PG(last_error_file) = NULL; } frankenphp_free_request_context(); +#ifndef PHP_WIN32 + if (is_forked_child) { + _exit(EG(exit_status)); + } +#endif go_frankenphp_after_script_execution(thread_index, EG(exit_status)); } zend_end_try();