Skip to content

Commit

Permalink
Fix zend_max_execution_timer.h cannot be included by the C++ extension.
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanFreeman committed Nov 24, 2024
1 parent 0f8f2be commit 4fd7788
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 4 deletions.
13 changes: 9 additions & 4 deletions ext-src/php_swoole.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions include/swoole_c_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down
8 changes: 8 additions & 0 deletions php_swoole.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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

Expand Down
4 changes: 4 additions & 0 deletions src/core/base.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 4fd7788

Please sign in to comment.