Skip to content

Commit f03cb84

Browse files
Add swoole coroutine hook docs (#4775)
Co-authored-by: Luffy <52o@qq52o.cn>
1 parent 09324fb commit f03cb84

File tree

5 files changed

+272
-0
lines changed

5 files changed

+272
-0
lines changed

reference/swoole/book.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
&reference.swoole.swoole.mysql.exception;
5151
&reference.swoole.swoole.process;
5252
&reference.swoole.swoole.redis.server;
53+
&reference.swoole.swoole.runtime;
5354
&reference.swoole.swoole.serialize;
5455
&reference.swoole.swoole.server;
5556
<!-- &reference.swoole.swoole.server.port; -->

reference/swoole/swoole.runtime.xml

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!-- $Revision$ -->
3+
4+
<reference xml:id="class.swoole-runtime" role="class" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xi="http://www.w3.org/2001/XInclude">
5+
6+
<title>The Swoole\Runtime class</title>
7+
<titleabbrev>Swoole\Runtime</titleabbrev>
8+
9+
<partintro>
10+
11+
<!-- {{{ Swoole\Runtime intro -->
12+
<section xml:id="swoole-runtime.intro">
13+
&reftitle.intro;
14+
<para>
15+
Swoole\Runtime provides coroutine support for various PHP functions through hook mechanism,
16+
allowing synchronous code to work asynchronously in coroutine environment.
17+
</para>
18+
</section>
19+
<!-- }}} -->
20+
21+
<section xml:id="swoole-runtime.synopsis">
22+
&reftitle.classsynopsis;
23+
24+
<!-- {{{ Synopsis -->
25+
<classsynopsis>
26+
<ooclass><classname>Swoole\Runtime</classname></ooclass>
27+
28+
<!-- {{{ Class synopsis -->
29+
<classsynopsisinfo>
30+
<ooclass>
31+
<classname>Swoole\Runtime</classname>
32+
</ooclass>
33+
</classsynopsisinfo>
34+
<!-- }}} -->
35+
36+
<classsynopsisinfo role="comment">&Methods;</classsynopsisinfo>
37+
<xi:include xpointer="xmlns(db=http://docbook.org/ns/docbook) xpointer(id('class.swoole-runtime')/db:refentry/db:refsect1[@role='description']/descendant::db:methodsynopsis[not(@role='procedural')])" />
38+
</classsynopsis>
39+
<!-- }}} -->
40+
41+
</section>
42+
43+
</partintro>
44+
45+
&reference.swoole.swoole.entities.runtime;
46+
47+
</reference>
48+
49+
<!-- Keep this comment at the end of the file
50+
Local variables:
51+
mode: sgml
52+
sgml-omittag:t
53+
sgml-shorttag:t
54+
sgml-minimize-attributes:nil
55+
sgml-always-quote-attributes:t
56+
sgml-indent-step:1
57+
sgml-indent-data:t
58+
indent-tabs-mode:nil
59+
sgml-parent-document:nil
60+
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
61+
sgml-exposed-tags:nil
62+
sgml-local-catalogs:nil
63+
sgml-local-ecat-files:nil
64+
End:
65+
vim600: syn=xml fen fdm=syntax fdl=2 si
66+
vim: et tw=78 syn=sgml
67+
vi: ts=1 sw=1
68+
-->
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!-- $Revision$ -->
3+
4+
<refentry xml:id="swoole-runtime.enable-coroutine" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
5+
<refnamediv>
6+
<refname>Swoole\Runtime::enableCoroutine</refname>
7+
<refpurpose>Enable coroutine for specified functions</refpurpose>
8+
</refnamediv>
9+
10+
<refsect1 role="description">
11+
&reftitle.description;
12+
<methodsynopsis>
13+
<modifier>public</modifier> <modifier>static</modifier> <type>void</type><methodname>Swoole\Runtime::enableCoroutine</methodname>
14+
<methodparam choice="opt"><type>int</type><parameter>flags</parameter><initializer>SWOOLE_HOOK_ALL</initializer></methodparam>
15+
</methodsynopsis>
16+
<para>
17+
This method enables coroutine support for specified PHP functions based on the given flags.
18+
It should be called once at the beginning of the application.
19+
</para>
20+
</refsect1>
21+
22+
<refsect1 role="parameters">
23+
&reftitle.parameters;
24+
<variablelist>
25+
<varlistentry>
26+
<term><parameter>flags</parameter></term>
27+
<listitem>
28+
<para>
29+
Bitmask of flags specifying which functions to hook. Can be combined using | operator.
30+
Available flags:
31+
<constant>SWOOLE_HOOK_TCP</constant>,
32+
<constant>SWOOLE_HOOK_UDP</constant>,
33+
<constant>SWOOLE_HOOK_UNIX</constant>,
34+
<constant>SWOOLE_HOOK_UDG</constant>,
35+
<constant>SWOOLE_HOOK_SSL</constant>,
36+
<constant>SWOOLE_HOOK_TLS</constant>,
37+
<constant>SWOOLE_HOOK_SLEEP</constant>,
38+
<constant>SWOOLE_HOOK_FILE</constant>,
39+
<constant>SWOOLE_HOOK_STREAM_FUNCTION</constant>,
40+
<constant>SWOOLE_HOOK_BLOCKING_FUNCTION</constant>,
41+
<constant>SWOOLE_HOOK_PROC</constant>,
42+
<constant>SWOOLE_HOOK_CURL</constant>,
43+
<constant>SWOOLE_HOOK_NATIVE_CURL</constant>,
44+
<constant>SWOOLE_HOOK_SOCKETS</constant>,
45+
<constant>SWOOLE_HOOK_STDIO</constant>,
46+
<constant>SWOOLE_HOOK_PDO_PGSQL</constant>,
47+
<constant>SWOOLE_HOOK_PDO_ODBC</constant>,
48+
<constant>SWOOLE_HOOK_PDO_ORACLE</constant>,
49+
<constant>SWOOLE_HOOK_PDO_SQLITE</constant>,
50+
or <constant>SWOOLE_HOOK_ALL</constant> for all flags.
51+
</para>
52+
</listitem>
53+
</varlistentry>
54+
</variablelist>
55+
</refsect1>
56+
57+
<refsect1 role="returnvalues">
58+
&reftitle.returnvalues;
59+
<para>
60+
&return.void;
61+
</para>
62+
</refsect1>
63+
</refentry>
64+
65+
<!-- Keep this comment at the end of the file
66+
Local variables:
67+
mode: sgml
68+
sgml-omittag:t
69+
sgml-shorttag:t
70+
sgml-minimize-attributes:nil
71+
sgml-always-quote-attributes:t
72+
sgml-indent-step:1
73+
sgml-indent-data:t
74+
indent-tabs-mode:nil
75+
sgml-parent-document:nil
76+
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
77+
sgml-exposed-tags:nil
78+
sgml-local-catalogs:nil
79+
sgml-local-ecat-files:nil
80+
End:
81+
vim600: syn=xml fen fdm=syntax fdl=2 si
82+
vim: et tw=78 syn=sgml
83+
vi: ts=1 sw=1
84+
-->
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!-- $Revision$ -->
3+
4+
<refentry xml:id="swoole-runtime.get-hook-flags" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
5+
<refnamediv>
6+
<refname>Swoole\Runtime::getHookFlags</refname>
7+
<refpurpose>Get current hook flags</refpurpose>
8+
</refnamediv>
9+
10+
<refsect1 role="description">
11+
&reftitle.description;
12+
<methodsynopsis>
13+
<modifier>public</modifier> <modifier>static</modifier> <type>int</type><methodname>Swoole\Runtime::getHookFlags</methodname>
14+
<void />
15+
</methodsynopsis>
16+
<para>
17+
Gets the current hook flags.
18+
Note that the returned flags might differ from what was set if some hooks failed.
19+
</para>
20+
</refsect1>
21+
22+
<refsect1 role="parameters">
23+
&reftitle.parameters;
24+
<para>
25+
This function has no parameters.
26+
</para>
27+
</refsect1>
28+
29+
<refsect1 role="returnvalues">
30+
&reftitle.returnvalues;
31+
<para>
32+
Returns the current hook flags as a bitmask.
33+
</para>
34+
</refsect1>
35+
</refentry>
36+
37+
<!-- Keep this comment at the end of the file
38+
Local variables:
39+
mode: sgml
40+
sgml-omittag:t
41+
sgml-shorttag:t
42+
sgml-minimize-attributes:nil
43+
sgml-always-quote-attributes:t
44+
sgml-indent-step:1
45+
sgml-indent-data:t
46+
indent-tabs-mode:nil
47+
sgml-parent-document:nil
48+
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
49+
sgml-exposed-tags:nil
50+
sgml-local-catalogs:nil
51+
sgml-local-ecat-files:nil
52+
End:
53+
vim600: syn=xml fen fdm=syntax fdl=2 si
54+
vim: et tw=78 syn=sgml
55+
vi: ts=1 sw=1
56+
-->
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!-- $Revision$ -->
3+
4+
<refentry xml:id="swoole-runtime.set-hook-flags" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
5+
<refnamediv>
6+
<refname>Swoole\Runtime::setHookFlags</refname>
7+
<refpurpose>Set hook flags for coroutine</refpurpose>
8+
</refnamediv>
9+
10+
<refsect1 role="description">
11+
&reftitle.description;
12+
<methodsynopsis>
13+
<modifier>public</modifier> <modifier>static</modifier> <type>bool</type><methodname>Swoole\Runtime::setHookFlags</methodname>
14+
<methodparam><type>int</type><parameter>flags</parameter></methodparam>
15+
</methodsynopsis>
16+
<para>
17+
Sets the hook flags for coroutine support.
18+
This dynamically changes the hook flags at runtime.
19+
</para>
20+
</refsect1>
21+
22+
<refsect1 role="parameters">
23+
&reftitle.parameters;
24+
<variablelist>
25+
<varlistentry>
26+
<term><parameter>flags</parameter></term>
27+
<listitem>
28+
<para>
29+
Bitmask of flags specifying which functions to hook. Same flags as enableCoroutine.
30+
</para>
31+
</listitem>
32+
</varlistentry>
33+
</variablelist>
34+
</refsect1>
35+
36+
<refsect1 role="returnvalues">
37+
&reftitle.returnvalues;
38+
<para>
39+
&return.success;
40+
</para>
41+
</refsect1>
42+
</refentry>
43+
44+
<!-- Keep this comment at the end of the file
45+
Local variables:
46+
mode: sgml
47+
sgml-omittag:t
48+
sgml-shorttag:t
49+
sgml-minimize-attributes:nil
50+
sgml-always-quote-attributes:t
51+
sgml-indent-step:1
52+
sgml-indent-data:t
53+
indent-tabs-mode:nil
54+
sgml-parent-document:nil
55+
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
56+
sgml-exposed-tags:nil
57+
sgml-local-catalogs:nil
58+
sgml-local-ecat-files:nil
59+
End:
60+
vim600: syn=xml fen fdm=syntax fdl=2 si
61+
vim: et tw=78 syn=sgml
62+
vi: ts=1 sw=1
63+
-->

0 commit comments

Comments
 (0)