Skip to content

optimize swoole event docs - #4774

Merged
jordikroon merged 3 commits into
php:masterfrom
NathanFreeman:event
Aug 12, 2026
Merged

optimize swoole event docs#4774
jordikroon merged 3 commits into
php:masterfrom
NathanFreeman:event

Conversation

@NathanFreeman

Copy link
Copy Markdown
Contributor

No description provided.

Comment thread reference/swoole/swoole/event/add.xml Outdated
Comment on lines +22 to +25
<para>
A socket that has already been added cannot be added again. Use swoole_event_set to
modify the corresponding callback functions and event types for the socket.
</para>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<para>
A socket that has already been added cannot be added again. Use swoole_event_set to
modify the corresponding callback functions and event types for the socket.
</para>
<simpara>
A socket that has already been added cannot be added again. Use swoole_event_set to
modify the corresponding callback functions and event types for the socket.
</simpara>

Comment thread reference/swoole/swoole/event/cycle.xml Outdated
Comment on lines +16 to +18
<para>
Defines a callback function to execute at the end (or beginning, if <parameter>before</parameter> is true) of each event loop iteration.
</para>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<para>
Defines a callback function to execute at the end (or beginning, if <parameter>before</parameter> is true) of each event loop iteration.
</para>
<simpara>
Defines a callback function to execute at the end (or beginning, if <parameter>before</parameter> is true) of each event loop iteration.
</simpara>

Comment thread reference/swoole/swoole/event/cycle.xml Outdated
Comment on lines +27 to +29
<para>
The function to execute. Set to <literal>null</literal> to clear a previously set cycle function.
</para>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<para>
The function to execute. Set to <literal>null</literal> to clear a previously set cycle function.
</para>
<simpara>
The function to execute. Set to <literal>null</literal> to clear a previously set cycle function.
</simpara>

Comment thread reference/swoole/swoole/event/cycle.xml Outdated
Comment on lines +35 to +37
<para>
If <literal>true</literal>, the callback executes before the event loop; if <literal>false</literal>, after.
</para>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<para>
If <literal>true</literal>, the callback executes before the event loop; if <literal>false</literal>, after.
</para>
<simpara>
If <literal>true</literal>, the callback executes before the event loop; if <literal>false</literal>, after.
</simpara>

Comment thread reference/swoole/swoole/event/cycle.xml Outdated
Comment on lines +45 to +47
<para>
&return.success;
</para>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<para>
&return.success;
</para>
<simpara>
&return.success;
</simpara>

<refsect1 role="description">
&reftitle.description;
<methodsynopsis>
<modifier>public</modifier> <modifier>static</modifier> <type>void</type><methodname>Swoole\Event::defer</methodname>

@lacatoire lacatoire Jun 22, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<modifier>public</modifier> <modifier>static</modifier> <type>void</type><methodname>Swoole\Event::defer</methodname>
<modifier>public</modifier> <modifier>static</modifier> <type>bool</type><methodname>Swoole\Event::defer</methodname>

&reftitle.description;
<methodsynopsis>
<modifier>public</modifier> <modifier>static</modifier> <type>void</type><methodname>Swoole\Event::exit</methodname>
<modifier>public</modifier> <modifier>static</modifier> <type>void</type><methodname>Swoole\Event::dispatch</methodname>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<modifier>public</modifier> <modifier>static</modifier> <type>void</type><methodname>Swoole\Event::dispatch</methodname>
<modifier>public</modifier> <modifier>static</modifier> <type>bool</type><methodname>Swoole\Event::dispatch</methodname>

<refsect1 role="description">
&reftitle.description;
<methodsynopsis>
<modifier>public</modifier> <modifier>static</modifier> <type>bool</type><methodname>Swoole\Event::isset</methodname>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<modifier>public</modifier> <modifier>static</modifier> <type>bool</type><methodname>Swoole\Event::isset</methodname>
<modifier>public</modifier> <modifier>static</modifier> <type>bool</type><methodname>Swoole\Event::isset</methodname>

Comment thread reference/swoole/swoole/event/isset.xml Outdated
Comment on lines +20 to +22
<para>
Checks whether the specified file descriptor is being monitored for the given event types in the event loop.
</para>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<para>
Checks whether the specified file descriptor is being monitored for the given event types in the event loop.
</para>
<simpara>
Checks whether the specified file descriptor is being monitored for the given event types in the event loop.
</simpara>

Comment thread reference/swoole/swoole/event/isset.xml Outdated
Comment on lines +39 to +41
<para>
Event types to check (bitmask of <constant>SWOOLE_EVENT_READ</constant> and/or <constant>SWOOLE_EVENT_WRITE</constant>).
</para>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<para>
Event types to check (bitmask of <constant>SWOOLE_EVENT_READ</constant> and/or <constant>SWOOLE_EVENT_WRITE</constant>).
</para>
<simpara>
Event types to check (bitmask of <constant>SWOOLE_EVENT_READ</constant> and/or <constant>SWOOLE_EVENT_WRITE</constant>).
</simpara>

Comment thread reference/swoole/swoole/event/isset.xml Outdated
Comment on lines +49 to +51
<para>
&return.success;
</para>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<para>
&return.success;
</para>
<simpara>
&return.success;
</simpara>

Comment thread reference/swoole/swoole.event.xml Outdated
Comment on lines +80 to +83
<para>
Swoole automatically converts Swoole\Process into UnixSocket and Swoole\Client
into connected client sockets at the underlying level.
</para>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<para>
Swoole automatically converts Swoole\Process into UnixSocket and Swoole\Client
into connected client sockets at the underlying level.
</para>
<simpara>
Swoole automatically converts Swoole\Process into UnixSocket and Swoole\Client
into connected client sockets at the underlying level.
</simpara>

Comment thread reference/swoole/swoole.event.xml Outdated
Comment on lines +68 to +71
<para>
Resources created by socket_create from the sockets extension require
the --enable-sockets flag during Swoole compilation.
</para>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<para>
Resources created by socket_create from the sockets extension require
the --enable-sockets flag during Swoole compilation.
</para>
<simpara>
Resources created by socket_create from the sockets extension require
the --enable-sockets flag during Swoole compilation.
</simpara>

Comment thread reference/swoole/swoole.event.xml Outdated
Comment on lines +57 to +59
<para>
Resources created by stream_socket_client/fsockopen.
</para>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<para>
Resources created by stream_socket_client/fsockopen.
</para>
<simpara>
Resources created by stream_socket_client/fsockopen.
</simpara>

Comment thread reference/swoole/swoole.event.xml Outdated
Comment on lines +46 to +48
<para>
File descriptors, including Swoole\Client->$sock, Swoole\Process->$pipe, or any other file descriptor (fd).
</para>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<para>
File descriptors, including Swoole\Client->$sock, Swoole\Process->$pipe, or any other file descriptor (fd).
</para>
<simpara>
File descriptors, including Swoole\Client->$sock, Swoole\Process->$pipe, or any other file descriptor (fd).
</simpara>

Comment thread reference/swoole/swoole.event.xml Outdated
Comment on lines +19 to +21
<para>
The Event module is low-level, being a basic encapsulation of epoll. Users should have experience with IO multiplexing programming.
</para>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<para>
The Event module is low-level, being a basic encapsulation of epoll. Users should have experience with IO multiplexing programming.
</para>
<simpara>
The Event module is low-level, being a basic encapsulation of epoll. Users should have experience with IO multiplexing programming.
</simpara>

Comment thread reference/swoole/swoole.event.xml Outdated
@@ -12,11 +12,81 @@
<section xml:id="swoole-event.intro">
&reftitle.intro;
<para>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<para>
<simpara>

Comment thread reference/swoole/swoole.event.xml Outdated

The Swoole extension provides low-level interfaces to directly manipulate the underlying epoll/kqueue/poll/select event loop.
It allows adding sockets created by other extensions or PHP's stream/socket extensions to Swoole's EventLoop.
</para>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
</para>
</simpara>

Comment thread reference/swoole/swoole/event/write.xml Outdated
<para>

&return.success;
</para>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
</para>
</simpara>

Comment thread reference/swoole/swoole/event/write.xml Outdated
@@ -45,11 +69,32 @@
<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<para>
<simpara>

<modifier>public</modifier> <modifier>static</modifier> <type>void</type><methodname>Swoole\Event::dispatch</methodname>
<void />
</methodsynopsis>
<para>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<para>
<simpara>

The purpose of this function is to maintain compatibility with some frameworks.
When a framework internally manages its own reactor loop, using Event::wait would allow
Swoole's underlying layer to retain control, preventing the framework from taking over execution.
</para>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
</para>
</simpara>

Comment thread reference/swoole/swoole/event/add.xml Outdated
<methodparam choice="opt"><type>string</type><parameter>events</parameter></methodparam>
<methodparam choice="opt"><type>int</type><parameter>flags</parameter></methodparam>
</methodsynopsis>
<para>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<para>
<simpara>

Comment thread reference/swoole/swoole/event/add.xml Outdated
<para>

Adds a socket to the underlying reactor event listener. This function can be used in both Server and Client modes.
</para>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
</para>
</simpara>

Comment thread reference/swoole/swoole/event/add.xml Outdated
<term><parameter>events</parameter></term>
<term><parameter>flags</parameter></term>
<listitem>
<para>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<para>
<simpara>

Comment thread reference/swoole/swoole/event/add.xml Outdated

Event type mask (e.g. <constant>SWOOLE_EVENT_READ</constant>, <constant>SWOOLE_EVENT_WRITE</constant>
or <constant>SWOOLE_EVENT_READ</constant> | <constant>SWOOLE_EVENT_WRITE</constant>).
</para>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
</para>
</simpara>

Comment thread reference/swoole/swoole/event/add.xml Outdated
@@ -63,11 +68,33 @@
<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<para>
<simpara>

Comment thread reference/swoole/swoole/event/add.xml Outdated
<para>

&return.success;
</para>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
</para>
</simpara>

Comment thread reference/swoole/swoole/event/add.xml Outdated
<varlistentry>
<term><parameter>read_callback</parameter></term>
<listitem>
<para>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<para>
<simpara>

Comment thread reference/swoole/swoole/event/set.xml Outdated
<varlistentry>
<term><parameter>write_callback</parameter></term>
<listitem>
<para>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<para>
<simpara>

Comment thread reference/swoole/swoole/event/set.xml Outdated
<para>

Callback function for writable events.
</para>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
</para>
</simpara>

Comment thread reference/swoole/swoole/event/set.xml Outdated
<term><parameter>events</parameter></term>
<term><parameter>flags</parameter></term>
<listitem>
<para>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<para>
<simpara>

Comment thread reference/swoole/swoole/event/set.xml Outdated

Event type mask (e.g. <constant>SWOOLE_EVENT_READ</constant>, <constant>SWOOLE_EVENT_WRITE</constant>
or <constant>SWOOLE_EVENT_READ</constant> | <constant>SWOOLE_EVENT_WRITE</constant>).
</para>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
</para>
</simpara>

Comment thread reference/swoole/swoole/event/set.xml Outdated
@@ -63,11 +91,9 @@
<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<para>
<simpara>

Comment thread reference/swoole/swoole/event/set.xml Outdated
<para>

&return.success;
</para>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
</para>
</simpara>

Comment thread reference/swoole/swoole/event/wait.xml Outdated
@@ -14,26 +13,36 @@
<void />
</methodsynopsis>
<para>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<para>
<simpara>

Comment thread reference/swoole/swoole/event/wait.xml Outdated
<para>

Starts the event loop. Place this at the end of your PHP program.
</para>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
</para>
</simpara>

Comment thread reference/swoole/swoole/event/wait.xml Outdated

<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<para>
<simpara>

Comment thread reference/swoole/swoole/event/wait.xml Outdated
<para>

No return value.
</para>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
</para>
</simpara>

<methodparam><type>string</type><parameter>data</parameter></methodparam>
<modifier>public</modifier> <modifier>static</modifier> <type>bool</type><methodname>Swoole\Event::write</methodname>
<methodparam><type>mixed</type><parameter>fd</parameter></methodparam>
<methodparam><type>mixed</type><parameter>data</parameter></methodparam>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<methodparam><type>mixed</type><parameter>data</parameter></methodparam>
<methodparam><type>string</type><parameter>data</parameter></methodparam>

Comment thread reference/swoole/swoole/event/write.xml Outdated
<methodparam><type>mixed</type><parameter>fd</parameter></methodparam>
<methodparam><type>mixed</type><parameter>data</parameter></methodparam>
</methodsynopsis>
<para>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<para>
<simpara>

Comment thread reference/swoole/swoole/event/write.xml Outdated
<para>

Makes data sending asynchronous for stream/sockets resources.
</para>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
</para>
</simpara>

Comment thread reference/swoole/swoole/event/write.xml Outdated
@@ -27,15 +51,15 @@
<term><parameter>fd</parameter></term>
<listitem>
<para>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<para>
<simpara>

Comment thread reference/swoole/swoole/event/write.xml Outdated
<para>

File descriptor (stream/socket resource, integer, or object).
</para>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
</para>
</simpara>

Comment thread reference/swoole/swoole/event/write.xml Outdated
<varlistentry>
<term><parameter>data</parameter></term>
<listitem>
<para>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<para>
<simpara>

Comment thread reference/swoole/swoole/event/write.xml Outdated
<para>

Data to send (length must not exceed socket buffer size).
</para>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
</para>
</simpara>

Comment thread reference/swoole/swoole.event.xml Outdated
<section xml:id="swoole-event.event-priority">
<title>Event Priority</title>
<orderedlist>
<listitem><para>Signal handler callback functions set via Process::signal</para></listitem>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<listitem><para>Signal handler callback functions set via Process::signal</para></listitem>
<listitem><simpara>Signal handler callback functions set via Process::signal</simpara></listitem>

Comment thread reference/swoole/swoole.event.xml Outdated
<title>Event Priority</title>
<orderedlist>
<listitem><para>Signal handler callback functions set via Process::signal</para></listitem>
<listitem><para>Timer callback functions set via Timer::tick and Timer::after</para></listitem>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<listitem><para>Timer callback functions set via Timer::tick and Timer::after</para></listitem>
<listitem><simpara>Timer callback functions set via Timer::tick and Timer::after</simpara></listitem>

Comment thread reference/swoole/swoole.event.xml Outdated
<orderedlist>
<listitem><para>Signal handler callback functions set via Process::signal</para></listitem>
<listitem><para>Timer callback functions set via Timer::tick and Timer::after</para></listitem>
<listitem><para>Deferred execution functions set via Event::defer</para></listitem>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<listitem><para>Deferred execution functions set via Event::defer</para></listitem>
<listitem><simpara>Deferred execution functions set via Event::defer</simpara></listitem>

Comment thread reference/swoole/swoole.event.xml Outdated
<listitem><para>Signal handler callback functions set via Process::signal</para></listitem>
<listitem><para>Timer callback functions set via Timer::tick and Timer::after</para></listitem>
<listitem><para>Deferred execution functions set via Event::defer</para></listitem>
<listitem><para>Periodic callback functions set via Event::cycle</para></listitem>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<listitem><para>Periodic callback functions set via Event::cycle</para></listitem>
<listitem><simpara>Periodic callback functions set via Event::cycle</simpara></listitem>

Comment thread reference/swoole/swoole/event/set.xml Outdated
<methodparam choice="opt"><type>callable</type><parameter>write_callback</parameter></methodparam>
<methodparam choice="opt"><type>int</type><parameter>flags</parameter></methodparam>
</methodsynopsis>
<para>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<para>
<simpara>

Comment thread reference/swoole/swoole/event/set.xml Outdated
<para>

Modifies the event listener callbacks and mask for the given file descriptor.
</para>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
</para>
</simpara>

</varlistentry>
<varlistentry>
<term><parameter>events</parameter></term>
<term><parameter>flags</parameter></term>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<term><parameter>flags</parameter></term>
<term><parameter>events</parameter></term>

@jordikroon

Copy link
Copy Markdown
Member

Hi @NathanFreeman. Thank you for this PR.
I have looked into it, and changed some style violations and a missing reference &reference.swoole.swoole.event.exit; which what I can see is a removed file within the changes.

I have not looked at the accuracy of the changes, nor have I merged the suggested changes in. I suggest you to have a quick look at those, and present hem in a follow-up PR if required.

Over the next few months, we will be migrating this extension to https://github.com/php/doc-extensions per RFC. So any follow-up PRs will likely have to target that repository based on its state.

@jordikroon
jordikroon merged commit 282797e into php:master Aug 12, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants