diff --git a/library/config.inc b/library/config.inc index d4782f586c4..70d362f4b01 100644 --- a/library/config.inc +++ b/library/config.inc @@ -4,6 +4,7 @@ return [ 'constants.php', # # 'std/array.php', + 'std/exec.php', # # 'ext/curl.php', # # diff --git a/library/std/exec.php b/library/std/exec.php new file mode 100644 index 00000000000..5497357e182 --- /dev/null +++ b/library/std/exec.php @@ -0,0 +1,26 @@ +add($fn, ...$args);\n" + " return $s->start();\n" + " }\n" + "}\n" + "\n" + "namespace Co {\n" + " function run(callable $fn, ...$args)\n" + " {\n" + " return \\Swoole\\Coroutine\\Run($fn, ...$args);\n" + " }\n" + "}\n"; + static void php_swoole_load_library() { zend::eval(swoole_library_source_constants, "@swoole-src/library/constants.php"); zend::eval(swoole_library_source_std_array, "@swoole-src/library/std/array.php"); + zend::eval(swoole_library_source_std_exec, "@swoole-src/library/std/exec.php"); zend::eval(swoole_library_source_ext_curl, "@swoole-src/library/ext/curl.php"); zend::eval(swoole_library_source_core_coroutine_wait_group, "@swoole-src/library/core/Coroutine/WaitGroup.php"); zend::eval(swoole_library_source_core_coroutine_object_pool, "@swoole-src/library/core/Coroutine/ObjectPool.php"); @@ -2037,4 +2090,5 @@ static void php_swoole_load_library() zend::eval(swoole_library_source_core_coroutine_server_connection, "@swoole-src/library/core/Coroutine/Server/Connection.php"); zend::eval(swoole_library_source_functions, "@swoole-src/library/functions.php"); zend::eval(swoole_library_source_alias, "@swoole-src/library/alias.php"); + zend::eval(swoole_library_source_alias_ns, "@swoole-src/library/alias_ns.php"); } diff --git a/swoole_runtime.cc b/swoole_runtime.cc index e97ee627ba6..e47657f79a0 100644 --- a/swoole_runtime.cc +++ b/swoole_runtime.cc @@ -1156,6 +1156,8 @@ bool PHPCoroutine::enable_hook(int flags) if (!(hook_flags & SW_HOOK_BLOCKING_FUNCTION)) { hook_func(ZEND_STRL("gethostbyname"), PHP_FN(swoole_coroutine_gethostbyname)); + hook_func(ZEND_STRL("exec")); + hook_func(ZEND_STRL("shell_exec")); } } else @@ -1163,6 +1165,8 @@ bool PHPCoroutine::enable_hook(int flags) if (hook_flags & SW_HOOK_BLOCKING_FUNCTION) { SW_UNHOOK_FUNC(gethostbyname); + unhook_func(ZEND_STRL("exec")); + unhook_func(ZEND_STRL("shell_exec")); } } diff --git a/tests/swoole_library/exec/exec/1.phpt b/tests/swoole_library/exec/exec/1.phpt new file mode 100644 index 00000000000..465b2890fcf --- /dev/null +++ b/tests/swoole_library/exec/exec/1.phpt @@ -0,0 +1,17 @@ +--TEST-- +swoole_library/std/exec: Test exec +--SKIPIF-- + +--FILE-- + +--EXPECT-- diff --git a/tests/swoole_library/exec/shell_exec/1.phpt b/tests/swoole_library/exec/shell_exec/1.phpt new file mode 100644 index 00000000000..22fdb1807a6 --- /dev/null +++ b/tests/swoole_library/exec/shell_exec/1.phpt @@ -0,0 +1,16 @@ +--TEST-- +swoole_library/std/exec: Test exec +--SKIPIF-- + +--FILE-- + +--EXPECT--