diff --git a/ext-src/php_swoole.cc b/ext-src/php_swoole.cc index 3dab63ba1a..ca2a94165b 100644 --- a/ext-src/php_swoole.cc +++ b/ext-src/php_swoole.cc @@ -17,13 +17,13 @@ #include "php_swoole_library.h" #include "php_swoole_process.h" -#if (HAVE_PCRE || HAVE_BUNDLED_PCRE) && !defined(COMPILE_DL_PCRE) -#include "ext/pcre/php_pcre.h" -#endif +BEGIN_EXTERN_C() #include "zend_exceptions.h" #include "zend_extensions.h" -BEGIN_EXTERN_C() +#if (HAVE_PCRE || HAVE_BUNDLED_PCRE) && !defined(COMPILE_DL_PCRE) +#include "ext/pcre/php_pcre.h" +#endif #include "ext/json/php_json.h" #include "stubs/php_swoole_arginfo.h" @@ -990,6 +990,10 @@ const swoole::Allocator *sw_zend_string_allocator() { return &zend_string_allocator; } +static void sw_after_fork(void *args) { + zend_max_execution_timer_init(); +} + PHP_RINIT_FUNCTION(swoole) { if (!SWOOLE_G(cli)) { return SUCCESS; @@ -1030,6 +1034,7 @@ PHP_RINIT_FUNCTION(swoole) { /* Disable warning even in ZEND_DEBUG because we may register our own signal handlers */ SIGG(check) = 0; #endif + swoole_add_hook(SW_GLOBAL_HOOK_AFTER_FORK, sw_after_fork, 0); php_swoole_http_server_rinit(); php_swoole_coroutine_rinit(); diff --git a/include/swoole_c_api.h b/include/swoole_c_api.h index 28e2783906..37c1211d56 100644 --- a/include/swoole_c_api.h +++ b/include/swoole_c_api.h @@ -39,6 +39,7 @@ enum swGlobalHookType { SW_GLOBAL_HOOK_ON_REACTOR_DESTROY, SW_GLOBAL_HOOK_BEFORE_SERVER_CREATE, SW_GLOBAL_HOOK_AFTER_SERVER_CREATE, + SW_GLOBAL_HOOK_AFTER_FORK, SW_GLOBAL_HOOK_USER = 24, SW_GLOBAL_HOOK_END = SW_MAX_HOOK_TYPE - 1, }; diff --git a/php_swoole.h b/php_swoole.h index aa6cb096f0..42e9ae3878 100644 --- a/php_swoole.h +++ b/php_swoole.h @@ -17,6 +17,10 @@ #ifndef PHP_SWOOLE_H #define PHP_SWOOLE_H +#ifdef __cplusplus +extern "C" { +#endif + #include "php.h" #include "php_ini.h" #include "php_globals.h" @@ -37,6 +41,10 @@ #include "config.h" #endif +#ifdef __cplusplus +} +#endif + extern zend_module_entry swoole_module_entry; #define phpext_swoole_ptr &swoole_module_entry diff --git a/src/core/base.cc b/src/core/base.cc index 81429beb59..2b81a31e5d 100644 --- a/src/core/base.cc +++ b/src/core/base.cc @@ -423,6 +423,10 @@ pid_t swoole_fork(int flags) { * reset signal handler */ swoole_signal_clear(); + + if (swoole_isset_hook(SW_GLOBAL_HOOK_AFTER_FORK)) { + swoole_call_hook(SW_GLOBAL_HOOK_AFTER_FORK, nullptr); + } } return pid;