From 727445e3fc17dc2d92303f4920c8faa60e4ffa78 Mon Sep 17 00:00:00 2001 From: NathanFreeman <1056159381@qq.com> Date: Sat, 12 Jul 2025 17:51:37 +0800 Subject: [PATCH] add swoole coroutine hook --- reference/swoole/book.xml | 1 + reference/swoole/swoole.runtime.xml | 68 +++++++++++++++ .../swoole/swoole/runtime/enableCoroutine.xml | 84 +++++++++++++++++++ .../swoole/swoole/runtime/getHookFlags.xml | 56 +++++++++++++ .../swoole/swoole/runtime/setHookFlags.xml | 63 ++++++++++++++ 5 files changed, 272 insertions(+) create mode 100644 reference/swoole/swoole.runtime.xml create mode 100644 reference/swoole/swoole/runtime/enableCoroutine.xml create mode 100644 reference/swoole/swoole/runtime/getHookFlags.xml create mode 100644 reference/swoole/swoole/runtime/setHookFlags.xml diff --git a/reference/swoole/book.xml b/reference/swoole/book.xml index c91dba43c695..fe0f4feeeff3 100644 --- a/reference/swoole/book.xml +++ b/reference/swoole/book.xml @@ -50,6 +50,7 @@ &reference.swoole.swoole.mysql.exception; &reference.swoole.swoole.process; &reference.swoole.swoole.redis.server; + &reference.swoole.swoole.runtime; &reference.swoole.swoole.serialize; &reference.swoole.swoole.server; diff --git a/reference/swoole/swoole.runtime.xml b/reference/swoole/swoole.runtime.xml new file mode 100644 index 000000000000..d96fd45b94e6 --- /dev/null +++ b/reference/swoole/swoole.runtime.xml @@ -0,0 +1,68 @@ + + + + + + The Swoole\Runtime class + Swoole\Runtime + + + + +
+ &reftitle.intro; + + Swoole\Runtime provides coroutine support for various PHP functions through hook mechanism, + allowing synchronous code to work asynchronously in coroutine environment. + +
+ + +
+ &reftitle.classsynopsis; + + + + Swoole\Runtime + + + + + Swoole\Runtime + + + + + &Methods; + + + + +
+ +
+ + &reference.swoole.swoole.entities.runtime; + +
+ + diff --git a/reference/swoole/swoole/runtime/enableCoroutine.xml b/reference/swoole/swoole/runtime/enableCoroutine.xml new file mode 100644 index 000000000000..343925593933 --- /dev/null +++ b/reference/swoole/swoole/runtime/enableCoroutine.xml @@ -0,0 +1,84 @@ + + + + + + Swoole\Runtime::enableCoroutine + Enable coroutine for specified functions + + + + &reftitle.description; + + public static voidSwoole\Runtime::enableCoroutine + intflagsSWOOLE_HOOK_ALL + + + This method enables coroutine support for specified PHP functions based on the given flags. + It should be called once at the beginning of the application. + + + + + &reftitle.parameters; + + + flags + + + Bitmask of flags specifying which functions to hook. Can be combined using | operator. + Available flags: + SWOOLE_HOOK_TCP, + SWOOLE_HOOK_UDP, + SWOOLE_HOOK_UNIX, + SWOOLE_HOOK_UDG, + SWOOLE_HOOK_SSL, + SWOOLE_HOOK_TLS, + SWOOLE_HOOK_SLEEP, + SWOOLE_HOOK_FILE, + SWOOLE_HOOK_STREAM_FUNCTION, + SWOOLE_HOOK_BLOCKING_FUNCTION, + SWOOLE_HOOK_PROC, + SWOOLE_HOOK_CURL, + SWOOLE_HOOK_NATIVE_CURL, + SWOOLE_HOOK_SOCKETS, + SWOOLE_HOOK_STDIO, + SWOOLE_HOOK_PDO_PGSQL, + SWOOLE_HOOK_PDO_ODBC, + SWOOLE_HOOK_PDO_ORACLE, + SWOOLE_HOOK_PDO_SQLITE, + or SWOOLE_HOOK_ALL for all flags. + + + + + + + + &reftitle.returnvalues; + + No return value. + + + + + diff --git a/reference/swoole/swoole/runtime/getHookFlags.xml b/reference/swoole/swoole/runtime/getHookFlags.xml new file mode 100644 index 000000000000..93b37eb271fb --- /dev/null +++ b/reference/swoole/swoole/runtime/getHookFlags.xml @@ -0,0 +1,56 @@ + + + + + + Swoole\Runtime::getHookFlags + Get current hook flags + + + + &reftitle.description; + + public static intSwoole\Runtime::getHookFlags + + + + Gets the current hook flags. + Note that the returned flags might differ from what was set if some hooks failed. + + + + + &reftitle.parameters; + + This function has no parameters. + + + + + &reftitle.returnvalues; + + Returns the current hook flags as a bitmask. + + + + + diff --git a/reference/swoole/swoole/runtime/setHookFlags.xml b/reference/swoole/swoole/runtime/setHookFlags.xml new file mode 100644 index 000000000000..6f9052c3d651 --- /dev/null +++ b/reference/swoole/swoole/runtime/setHookFlags.xml @@ -0,0 +1,63 @@ + + + + + + Swoole\Runtime::setHookFlags + Set hook flags for coroutine + + + + &reftitle.description; + + public static boolSwoole\Runtime::setHookFlags + intflags + + + Sets the hook flags for coroutine support. + This dynamically changes the hook flags at runtime. + + + + + &reftitle.parameters; + + + flags + + + Bitmask of flags specifying which functions to hook. Same flags as enableCoroutine. + + + + + + + + &reftitle.returnvalues; + + &return.success; + + + + +