Skip to content

add swoole coroutine hook docs #4775

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions reference/swoole/book.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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;
<!-- &reference.swoole.swoole.server.port; -->
Expand Down
68 changes: 68 additions & 0 deletions reference/swoole/swoole.runtime.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->

<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">

<title>The Swoole\Runtime class</title>
<titleabbrev>Swoole\Runtime</titleabbrev>

<partintro>

<!-- {{{ Swoole\Runtime intro -->
<section xml:id="swoole-runtime.intro">
&reftitle.intro;
<para>
Swoole\Runtime provides coroutine support for various PHP functions through hook mechanism,
allowing synchronous code to work asynchronously in coroutine environment.
</para>
</section>
<!-- }}} -->

<section xml:id="swoole-runtime.synopsis">
&reftitle.classsynopsis;

<!-- {{{ Synopsis -->
<classsynopsis>
<ooclass><classname>Swoole\Runtime</classname></ooclass>

<!-- {{{ Class synopsis -->
<classsynopsisinfo>
<ooclass>
<classname>Swoole\Runtime</classname>
</ooclass>
</classsynopsisinfo>
<!-- }}} -->

<classsynopsisinfo role="comment">&Methods;</classsynopsisinfo>
<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')])" />
</classsynopsis>
<!-- }}} -->

</section>

</partintro>

&reference.swoole.swoole.entities.runtime;

</reference>

<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->
84 changes: 84 additions & 0 deletions reference/swoole/swoole/runtime/enableCoroutine.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->

<refentry xml:id="swoole-runtime.enable-coroutine" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
<refnamediv>
<refname>Swoole\Runtime::enableCoroutine</refname>
<refpurpose>Enable coroutine for specified functions</refpurpose>
</refnamediv>

<refsect1 role="description">
&reftitle.description;
<methodsynopsis>
<modifier>public</modifier> <modifier>static</modifier> <type>void</type><methodname>Swoole\Runtime::enableCoroutine</methodname>
<methodparam choice="opt"><type>int</type><parameter>flags</parameter><initializer>SWOOLE_HOOK_ALL</initializer></methodparam>
</methodsynopsis>
<para>
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.
</para>
</refsect1>

<refsect1 role="parameters">
&reftitle.parameters;
<variablelist>
<varlistentry>
<term><parameter>flags</parameter></term>
<listitem>
<para>
Bitmask of flags specifying which functions to hook. Can be combined using | operator.
Available flags:
<constant>SWOOLE_HOOK_TCP</constant>,
<constant>SWOOLE_HOOK_UDP</constant>,
<constant>SWOOLE_HOOK_UNIX</constant>,
<constant>SWOOLE_HOOK_UDG</constant>,
<constant>SWOOLE_HOOK_SSL</constant>,
<constant>SWOOLE_HOOK_TLS</constant>,
<constant>SWOOLE_HOOK_SLEEP</constant>,
<constant>SWOOLE_HOOK_FILE</constant>,
<constant>SWOOLE_HOOK_STREAM_FUNCTION</constant>,
<constant>SWOOLE_HOOK_BLOCKING_FUNCTION</constant>,
<constant>SWOOLE_HOOK_PROC</constant>,
<constant>SWOOLE_HOOK_CURL</constant>,
<constant>SWOOLE_HOOK_NATIVE_CURL</constant>,
<constant>SWOOLE_HOOK_SOCKETS</constant>,
<constant>SWOOLE_HOOK_STDIO</constant>,
<constant>SWOOLE_HOOK_PDO_PGSQL</constant>,
<constant>SWOOLE_HOOK_PDO_ODBC</constant>,
<constant>SWOOLE_HOOK_PDO_ORACLE</constant>,
<constant>SWOOLE_HOOK_PDO_SQLITE</constant>,
or <constant>SWOOLE_HOOK_ALL</constant> for all flags.
</para>
</listitem>
</varlistentry>
</variablelist>
</refsect1>

<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
No return value.
</para>
</refsect1>
</refentry>

<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->
56 changes: 56 additions & 0 deletions reference/swoole/swoole/runtime/getHookFlags.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->

<refentry xml:id="swoole-runtime.get-hook-flags" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
<refnamediv>
<refname>Swoole\Runtime::getHookFlags</refname>
<refpurpose>Get current hook flags</refpurpose>
</refnamediv>

<refsect1 role="description">
&reftitle.description;
<methodsynopsis>
<modifier>public</modifier> <modifier>static</modifier> <type>int</type><methodname>Swoole\Runtime::getHookFlags</methodname>
<void />
</methodsynopsis>
<para>
Gets the current hook flags.
Note that the returned flags might differ from what was set if some hooks failed.
</para>
</refsect1>

<refsect1 role="parameters">
&reftitle.parameters;
<para>
This function has no parameters.
</para>
</refsect1>

<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
Returns the current hook flags as a bitmask.
</para>
</refsect1>
</refentry>

<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->
63 changes: 63 additions & 0 deletions reference/swoole/swoole/runtime/setHookFlags.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->

<refentry xml:id="swoole-runtime.set-hook-flags" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
<refnamediv>
<refname>Swoole\Runtime::setHookFlags</refname>
<refpurpose>Set hook flags for coroutine</refpurpose>
</refnamediv>

<refsect1 role="description">
&reftitle.description;
<methodsynopsis>
<modifier>public</modifier> <modifier>static</modifier> <type>bool</type><methodname>Swoole\Runtime::setHookFlags</methodname>
<methodparam><type>int</type><parameter>flags</parameter></methodparam>
</methodsynopsis>
<para>
Sets the hook flags for coroutine support.
This dynamically changes the hook flags at runtime.
</para>
</refsect1>

<refsect1 role="parameters">
&reftitle.parameters;
<variablelist>
<varlistentry>
<term><parameter>flags</parameter></term>
<listitem>
<para>
Bitmask of flags specifying which functions to hook. Same flags as enableCoroutine.
</para>
</listitem>
</varlistentry>
</variablelist>
</refsect1>

<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
&return.success;
</para>
</refsect1>
</refentry>

<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->