Skip to content

Commit 54475b7

Browse files
committed
Fix PHP execution limit timer error.
1 parent cc6afa5 commit 54475b7

File tree

4 files changed

+33
-10
lines changed

4 files changed

+33
-10
lines changed

ext-src/php_swoole.cc

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@
1818
#include "php_swoole_process.h"
1919
#include "php_swoole_thread.h"
2020

21-
#if (HAVE_PCRE || HAVE_BUNDLED_PCRE) && !defined(COMPILE_DL_PCRE)
22-
#include "ext/pcre/php_pcre.h"
23-
#endif
21+
BEGIN_EXTERN_C()
2422
#include "zend_exceptions.h"
2523
#include "zend_extensions.h"
2624

27-
BEGIN_EXTERN_C()
25+
#if (HAVE_PCRE || HAVE_BUNDLED_PCRE) && !defined(COMPILE_DL_PCRE)
26+
#include "ext/pcre/php_pcre.h"
27+
#endif
2828
#include "ext/json/php_json.h"
2929

3030
#include "stubs/php_swoole_arginfo.h"
@@ -1031,6 +1031,19 @@ const swoole::Allocator *sw_zend_string_allocator() {
10311031
return &zend_string_allocator;
10321032
}
10331033

1034+
void sw_php_exit(int status) {
1035+
EG(exit_status) = status;
1036+
#ifdef SW_THREAD
1037+
php_swoole_thread_bailout();
1038+
#else
1039+
zend_bailout();
1040+
#endif
1041+
}
1042+
1043+
static void sw_after_fork(void *args) {
1044+
zend_max_execution_timer_init();
1045+
}
1046+
10341047
PHP_RINIT_FUNCTION(swoole) {
10351048
if (!SWOOLE_G(cli)) {
10361049
return SUCCESS;
@@ -1071,6 +1084,8 @@ PHP_RINIT_FUNCTION(swoole) {
10711084
SIGG(check) = 0;
10721085
#endif
10731086

1087+
swoole_add_hook(SW_GLOBAL_HOOK_AFTER_FORK, sw_after_fork, 0);
1088+
10741089
php_swoole_http_server_rinit();
10751090
php_swoole_websocket_server_rinit();
10761091
php_swoole_coroutine_rinit();
@@ -1517,12 +1532,7 @@ static PHP_FUNCTION(swoole_implicit_fn) {
15171532
swoole_fatal_error(SW_ERROR_FOR_TEST, "test");
15181533
php_printf("never be executed here\n");
15191534
} else if (SW_STRCASEEQ(fn, l_fn, "bailout")) {
1520-
EG(exit_status) = zargs ? zval_get_long(zargs) : 95;
1521-
#ifdef SW_THREAD
1522-
php_swoole_thread_bailout();
1523-
#else
1524-
zend_bailout();
1525-
#endif
1535+
sw_php_exit(zargs ? zval_get_long(zargs) : 95);
15261536
} else if (SW_STRCASEEQ(fn, l_fn, "abort")) {
15271537
abort();
15281538
} else {

include/swoole_c_api.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ enum swGlobalHookType {
3939
SW_GLOBAL_HOOK_ON_REACTOR_DESTROY,
4040
SW_GLOBAL_HOOK_BEFORE_SERVER_CREATE,
4141
SW_GLOBAL_HOOK_AFTER_SERVER_CREATE,
42+
SW_GLOBAL_HOOK_AFTER_FORK,
4243
SW_GLOBAL_HOOK_USER = 24,
4344
SW_GLOBAL_HOOK_END = SW_MAX_HOOK_TYPE - 1,
4445
};

php_swoole.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717
#ifndef PHP_SWOOLE_H
1818
#define PHP_SWOOLE_H
1919

20+
#ifdef __cplusplus
21+
extern "C" {
22+
#endif
23+
2024
#include "php.h"
2125
#include "php_ini.h"
2226
#include "php_globals.h"
@@ -37,6 +41,10 @@
3741
#include "config.h"
3842
#endif
3943

44+
#ifdef __cplusplus
45+
}
46+
#endif
47+
4048
extern zend_module_entry swoole_module_entry;
4149
#define phpext_swoole_ptr &swoole_module_entry
4250

src/core/base.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,10 @@ pid_t swoole_fork(int flags) {
397397
* reset signal handler
398398
*/
399399
swoole_signal_clear();
400+
401+
if (swoole_isset_hook(SW_GLOBAL_HOOK_AFTER_FORK)) {
402+
swoole_call_hook(SW_GLOBAL_HOOK_AFTER_FORK, nullptr);
403+
}
400404
}
401405

402406
return pid;

0 commit comments

Comments
 (0)