[doc-en] master: PHP 8.6: Document Io\Poll\Context (#6130)
| From: | Louis-Arnaud via GitHub | Date: | Sat, 28 Nov 2026 22:43:19 +0000 |
| Subject: | [doc-en] master: PHP 8.6: Document Io\Poll\Context (#6130) | ||
| Groups: | php.doc.cvs | ||
| Request: | Send a blank email to doc-cvs+get-24034@lists.php.net to get a copy of this message | ||
Author: Louis-Arnaud (lacatoire)
Committer: GitHub (web-flow)
Pusher: lacatoire
Date: 2026-11-28T23:43:16+01:00
Commit: https://github.com/php/doc-en/commit/0af738075e16a7ea2f263a60fa43429910a01d16
Raw diff: https://github.com/php/doc-en/commit/0af738075e16a7ea2f263a60fa43429910a01d16.diff
PHP 8.6: Document Io\Poll\Context (#6130)
* PHP 8.6: Document the polling API
* Keep only Io\Poll\Context, fix the build
* PHP 8.6: Document the Io\Poll enums, Io\Poll\Handle and StreamPollHandle
* Update wait.xml
Co-authored-by: Jordi Kroon <jordikroon@php.net>
* Update io.poll.event.xml
Co-authored-by: Jordi Kroon <jordikroon@php.net>
* Update streampollhandle.xml
Co-authored-by: Jordi Kroon <jordikroon@php.net>
---------
Co-authored-by: Jordi Kroon <jordikroon@php.net>
Changed paths:
A reference/io/book.xml
A reference/io/io.poll.backend.xml
A reference/io/io.poll.context.xml
A reference/io/io.poll.event.xml
A reference/io/io.poll.handle.xml
A reference/io/io/poll/backend/getavailablebackends.xml
A reference/io/io/poll/backend/isavailable.xml
A reference/io/io/poll/backend/supportsedgetriggering.xml
A reference/io/io/poll/context/add.xml
A reference/io/io/poll/context/construct.xml
A reference/io/io/poll/context/getbackend.xml
A reference/io/io/poll/context/wait.xml
A reference/io/streampollhandle.xml
A reference/io/streampollhandle/construct.xml
A reference/io/streampollhandle/getstream.xml
A reference/io/streampollhandle/isvalid.xml
A reference/io/versions.xml
M appendices/extensions.xml
M manual.xml
M reference/datetime/time.duration.xml
M reference/stream/functions/stream-select.xml
Diff:
diff --git a/appendices/extensions.xml b/appendices/extensions.xml
index 302fd4ce2920..a1eb158822d5 100644
--- a/appendices/extensions.xml
+++ b/appendices/extensions.xml
@@ -63,6 +63,7 @@
<listitem><simpara><xref
linkend="book.info"/></simpara></listitem>
<listitem><simpara><xref
linkend="book.inotify"/></simpara></listitem>
<listitem><simpara><xref
linkend="book.intl"/></simpara></listitem>
+ <listitem><simpara><xref
linkend="book.io"/></simpara></listitem>
<listitem><simpara><xref
linkend="book.json"/></simpara></listitem>
<listitem><simpara><xref
linkend="book.ldap"/></simpara></listitem>
<listitem><simpara><xref
linkend="book.libxml"/></simpara></listitem>
@@ -213,6 +214,7 @@
<listitem><para><xref
linkend="book.funchand"/></para></listitem>
<listitem><para><xref
linkend="book.hash"/></para></listitem>
<listitem><para><xref
linkend="book.info"/></para></listitem>
+ <listitem><para><xref
linkend="book.io"/></para></listitem>
<listitem><para><xref
linkend="book.json"/></para></listitem>
<listitem><para><xref
linkend="book.mail"/></para></listitem>
<listitem><para><xref
linkend="book.math"/></para></listitem>
diff --git a/manual.xml b/manual.xml
index d9302073d28d..6c251774091a 100644
--- a/manual.xml
+++ b/manual.xml
@@ -272,6 +272,7 @@
&reference.geoip.book;
&reference.fann.book;
&reference.igbinary.book;
+ &reference.io.book;
&reference.json.book;
&reference.simdjson.book;
&reference.lua.book;
diff --git a/reference/datetime/time.duration.xml b/reference/datetime/time.duration.xml
index 077656f739a0..fbed87f36b19 100644
--- a/reference/datetime/time.duration.xml
+++ b/reference/datetime/time.duration.xml
@@ -24,8 +24,8 @@
Use <classname>DateInterval</classname> for calendar arithmetic on
<classname>DateTimeImmutable</classname> objects, and
<classname>Time\Duration</classname> for unambiguous amounts of time,
- for example the <parameter>timeout</parameter> of the
- <acronym>I/O</acronym> polling <acronym>API</acronym>.
+ for example the <parameter>timeout</parameter> of
+ <methodname>Io\Poll\Context::wait</methodname>.
</simpara>
<simpara>
Objects of this class are immutable.
diff --git a/reference/io/book.xml b/reference/io/book.xml
new file mode 100644
index 000000000000..d96a1db8cf05
--- /dev/null
+++ b/reference/io/book.xml
@@ -0,0 +1,59 @@
+<?xml version="1.0" encoding="utf-8"?>
+<book xml:id="book.io" xmlns="http://docbook.org/ns/docbook"
xmlns:xlink="http://www.w3.org/1999/xlink">
+ <?phpdoc extension-membership="core" ?>
+ <title>Input/Output</title>
+ <titleabbrev>IO</titleabbrev>
+
+ <preface xml:id="intro.io">
+ &reftitle.intro;
+ <simpara>
+ The classes of the <literal>Io</literal> namespace provide a polling
+ <acronym>API</acronym>: a way to wait until one of many streams is ready
+ for reading or writing, using the polling mechanism of the operating
+ system.
+ It is intended for programs that handle many connections at once, such as
+ servers and event loops.
+ </simpara>
+ <simpara>
+ The handles to watch are registered with an
+ <classname>Io\Poll\Context</classname>, which returns an
+ <classname>Io\Poll\Watcher</classname> for each of them.
+ <methodname>Io\Poll\Context::wait</methodname> then blocks until some of
+ the watchers are triggered.
+ Streams are wrapped in a <classname>StreamPollHandle</classname> to be
+ watched.
+ </simpara>
+ <simpara>
+ These classes are part of the PHP core and are always available.
+ </simpara>
+ </preface>
+
+ &reference.io.io.poll.context;
+
+ &reference.io.io.poll.handle;
+ &reference.io.streampollhandle;
+
+ &reference.io.io.poll.backend;
+ &reference.io.io.poll.event;
+
+</book>
+<!-- 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
+-->
diff --git a/reference/io/io.poll.backend.xml b/reference/io/io.poll.backend.xml
new file mode 100644
index 000000000000..f5369b81f146
--- /dev/null
+++ b/reference/io/io.poll.backend.xml
@@ -0,0 +1,113 @@
+<?xml version="1.0" encoding="utf-8"?>
+<reference xml:id="enum.io-poll-backend" role="enum" xmlns="http://docbook.org/ns/docbook"
xmlns:xlink="http://www.w3.org/1999/xlink">
+ <title>The Io\Poll\Backend enum</title>
+ <titleabbrev>Io\Poll\Backend</titleabbrev>
+
+ <partintro>
+ <section xml:id="enum.io-poll-backend.intro">
+ &reftitle.intro;
+ <simpara>
+ The <enumname>Io\Poll\Backend</enumname> enum lists the polling mechanisms
+ an <classname>Io\Poll\Context</classname> can use.
+ Which of them are available depends on the operating system.
+ </simpara>
+ <simpara>
+ In addition to its cases, the enum provides the
+ <methodname>Io\Poll\Backend::getAvailableBackends</methodname>,
+ <methodname>Io\Poll\Backend::isAvailable</methodname> and
+ <methodname>Io\Poll\Backend::supportsEdgeTriggering</methodname> methods.
+ </simpara>
+ </section>
+
+ <section xml:id="enum.io-poll-backend.synopsis">
+ &reftitle.enumsynopsis;
+
+ <packagesynopsis>
+ <package>Io\Poll</package>
+
+ <enumsynopsis>
+ <enumname>Backend</enumname>
+
+ <enumitem>
+ <enumidentifier>Auto</enumidentifier>
+ <enumitemdescription>
+ Selects the most suitable backend available on the platform: event
+ ports, kqueue or epoll if one of them is available, and otherwise
+ <literal>WSAPoll</literal> on Windows and <literal>poll</literal>
+ elsewhere.
+ This is the default.
+ </enumitemdescription>
+ </enumitem>
+
+ <enumitem>
+ <enumidentifier>Poll</enumidentifier>
+ <enumitemdescription>
+ The <literal>poll</literal> system call, available on all platforms
+ except Windows.
+ </enumitemdescription>
+ </enumitem>
+
+ <enumitem>
+ <enumidentifier>Epoll</enumidentifier>
+ <enumitemdescription>
+ The <literal>epoll</literal> interface of Linux.
+ </enumitemdescription>
+ </enumitem>
+
+ <enumitem>
+ <enumidentifier>Kqueue</enumidentifier>
+ <enumitemdescription>
+ The <literal>kqueue</literal> interface of macOS and the BSD systems.
+ </enumitemdescription>
+ </enumitem>
+
+ <enumitem>
+ <enumidentifier>EventPorts</enumidentifier>
+ <enumitemdescription>
+ The event ports of Solaris and illumos.
+ </enumitemdescription>
+ </enumitem>
+
+ <enumitem>
+ <enumidentifier>WSAPoll</enumidentifier>
+ <enumitemdescription>
+ The <literal>WSAPoll</literal> function of Windows.
+ </enumitemdescription>
+ </enumitem>
+ </enumsynopsis>
+ </packagesynopsis>
+ </section>
+
+ <section role="seealso">
+ &reftitle.seealso;
+ <simplelist>
+ <member><methodname>Io\Poll\Context::__construct</methodname></member>
+ <member><methodname>Io\Poll\Context::getBackend</methodname></member>
+ <member><enumname>Io\Poll\Event</enumname></member>
+ </simplelist>
+ </section>
+ </partintro>
+
+ &reference.io.io.poll.entities.backend;
+
+</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
+-->
diff --git a/reference/io/io.poll.context.xml b/reference/io/io.poll.context.xml
new file mode 100644
index 000000000000..e798ad729923
--- /dev/null
+++ b/reference/io/io.poll.context.xml
@@ -0,0 +1,107 @@
+<?xml version="1.0" encoding="utf-8"?>
+<reference xml:id="class.io-poll-context" 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 Io\Poll\Context class</title>
+ <titleabbrev>Io\Poll\Context</titleabbrev>
+
+ <partintro>
+ <section xml:id="io-poll-context.intro">
+ &reftitle.intro;
+ <simpara>
+ A polling context watches a set of handles and reports which of them are
+ ready for reading or writing.
+ It is the entry point of the polling <acronym>API</acronym>: handles are
+ registered with <methodname>Io\Poll\Context::add</methodname>, and
+ <methodname>Io\Poll\Context::wait</methodname> blocks until one of them is
+ ready.
+ </simpara>
+ <simpara>
+ The context relies on the polling mechanism of the operating system,
+ represented by the <enumname>Io\Poll\Backend</enumname> enum.
+ Unlike <function>stream_select</function>, the set of watched streams is
+ kept between calls instead of being passed again on each of them.
+ </simpara>
+ <simpara>
+ Objects of this class cannot be cloned or serialized.
+ </simpara>
+ </section>
+
+ <section xml:id="io-poll-context.synopsis">
+ &reftitle.classsynopsis;
+
+ <packagesynopsis>
+ <package>Io\Poll</package>
+
+ <classsynopsis class="class">
+ <ooclass>
+ <modifier>final</modifier>
+ <classname>Context</classname>
+ </ooclass>
+
+ <classsynopsisinfo role="comment">&Methods;</classsynopsisinfo>
+ <xi:include xpointer="xmlns(db=http://docbook.org/ns/docbook)
xpointer(id('class.io-poll-context')/db:refentry/db:refsect1[@role='description']/descendant::db:constructorsynopsis[@role='Io\\Poll\\Context'])"/>
+ <xi:include xpointer="xmlns(db=http://docbook.org/ns/docbook)
xpointer(id('class.io-poll-context')/db:refentry/db:refsect1[@role='description']/descendant::db:methodsynopsis[@role='Io\\Poll\\Context'])"/>
+ </classsynopsis>
+ </packagesynopsis>
+ </section>
+
+ <section xml:id="io-poll-context.examples">
+ &reftitle.examples;
+ <example xml:id="io-poll-context.examples.basic">
+ <title>Waiting for a stream to become readable</title>
+ <programlisting role="php">
+<![CDATA[
+<?php
+use Io\Poll\Context;
+use Io\Poll\Event;
+use Time\Duration;
+
+[$reader, $writer] = stream_socket_pair(STREAM_PF_UNIX, STREAM_SOCK_STREAM, STREAM_IPPROTO_IP);
+
+$context = new Context();
+$context->add(new StreamPollHandle($reader), [Event::Read], 'reader');
+
+// Nothing can be read yet, so the wait times out.
+var_dump(count($context->wait(Duration::fromMilliseconds(10))));
+
+fwrite($writer, 'ping');
+
+foreach ($context->wait(Duration::fromSeconds(1)) as $watcher) {
+ $stream = $watcher->getHandle()->getStream();
+ echo $watcher->getData(), ': ', fread($stream, 1024), PHP_EOL;
+}
+]]>
+ </programlisting>
+ &example.outputs;
+ <screen>
+<![CDATA[
+int(0)
+reader: ping
+]]>
+ </screen>
+ </example>
+ </section>
+ </partintro>
+
+ &reference.io.io.poll.entities.context;
+
+</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
+-->
diff --git a/reference/io/io.poll.event.xml b/reference/io/io.poll.event.xml
new file mode 100644
index 000000000000..2617721202ef
--- /dev/null
+++ b/reference/io/io.poll.event.xml
@@ -0,0 +1,169 @@
+<?xml version="1.0" encoding="utf-8"?>
+<reference xml:id="enum.io-poll-event" role="enum" xmlns="http://docbook.org/ns/docbook"
xmlns:xlink="http://www.w3.org/1999/xlink">
+ <title>The Io\Poll\Event enum</title>
+ <titleabbrev>Io\Poll\Event</titleabbrev>
+
+ <partintro>
+ <section xml:id="enum.io-poll-event.intro">
+ &reftitle.intro;
+ <simpara>
+ The <enumname>Io\Poll\Event</enumname> enum lists the conditions an
+ <classname>Io\Poll\Context</classname> can watch for and report, together
+ with two modifiers that change how they are reported.
+ </simpara>
+ <simpara>
+ A list of cases is passed to
+ <methodname>Io\Poll\Context::add</methodname>,
+ <methodname>Io\Poll\Watcher::modify</methodname> and
+ <methodname>Io\Poll\Watcher::modifyEvents</methodname>, and returned by
+ <methodname>Io\Poll\Watcher::getWatchedEvents</methodname> and
+ <methodname>Io\Poll\Watcher::getTriggeredEvents</methodname>.
+ </simpara>
+ </section>
+
+ <section xml:id="enum.io-poll-event.synopsis">
+ &reftitle.enumsynopsis;
+
+ <packagesynopsis>
+ <package>Io\Poll</package>
+
+ <enumsynopsis>
+ <enumname>Event</enumname>
+
+ <enumitem>
+ <enumidentifier>Read</enumidentifier>
+ <enumitemdescription>
+ Data is available for reading.
+ For a listening socket, a connection is ready to be accepted.
+ This event is also reported when the end of the stream is reached, for
+ example when the peer closed a TCP connection.
+ </enumitemdescription>
+ </enumitem>
+
+ <enumitem>
+ <enumidentifier>Write</enumidentifier>
+ <enumitemdescription>
+ Data can be written without blocking.
+ </enumitemdescription>
+ </enumitem>
+
+ <enumitem>
+ <enumidentifier>Error</enumidentifier>
+ <enumitemdescription>
+ An error occurred on the handle.
+ This event is reported even if it was not requested.
+ </enumitemdescription>
+ </enumitem>
+
+ <enumitem>
+ <enumidentifier>HangUp</enumidentifier>
+ <enumitemdescription>
+ The handle was hung up, for example because the other end of a pipe or
+ of a Unix domain socket pair was closed.
+ This event is reported even if it was not requested.
+ </enumitemdescription>
+ </enumitem>
+
+ <enumitem>
+ <enumidentifier>ReadHangUp</enumidentifier>
+ <enumitemdescription>
+ The other end closed the connection or shut down its writing half.
+ This event is only reported if it was requested, and only by
+ <constant>Io\Poll\Backend::Epoll</constant>.
+ </enumitemdescription>
+ </enumitem>
+
+ <enumitem>
+ <enumidentifier>OneShot</enumidentifier>
+ <enumitemdescription>
+ A modifier: the watcher is reported once, and then stays silent until
+ its events are set again with
+ <methodname>Io\Poll\Watcher::modify</methodname> or
+ <methodname>Io\Poll\Watcher::modifyEvents</methodname>.
+ </enumitemdescription>
+ </enumitem>
+
+ <enumitem>
+ <enumidentifier>EdgeTriggered</enumidentifier>
+ <enumitemdescription>
+ A modifier: the watcher is reported when its state changes, for example
+ when new data arrives, instead of for as long as the condition holds.
+ It is only supported by the backends for which
+ <methodname>Io\Poll\Backend::supportsEdgeTriggering</methodname>
+ returns &true;.
+ </enumitemdescription>
+ </enumitem>
+ </enumsynopsis>
+ </packagesynopsis>
+ </section>
+
+ <section xml:id="enum.io-poll-event.examples">
+ &reftitle.examples;
+ <example xml:id="enum.io-poll-event.examples.edge-triggered">
+ <title>Level-triggered and edge-triggered reporting</title>
+ <programlisting role="php">
+<![CDATA[
+<?php
+use Io\Poll\Context;
+use Io\Poll\Event;
+use Time\Duration;
+
+[$reader, $writer] = stream_socket_pair(STREAM_PF_UNIX, STREAM_SOCK_STREAM, STREAM_IPPROTO_IP);
+
+// Requires a backend that supports edge triggering, see
+// Io\Poll\Backend::supportsEdgeTriggering().
+$context = new Context();
+$context->add(new StreamPollHandle($reader), [Event::Read, Event::EdgeTriggered]);
+
+fwrite($writer, 'ping');
+var_dump(count($context->wait(Duration::fromMilliseconds(10))));
+
+// The data was not read, but the readiness is not reported a second time.
+var_dump(count($context->wait(Duration::fromMilliseconds(10))));
+
+fwrite($writer, 'pong');
+var_dump(count($context->wait(Duration::fromMilliseconds(10))));
+]]>
+ </programlisting>
+ &example.outputs.similar;
+ <screen>
+<![CDATA[
+int(1)
+int(0)
+int(1)
+]]>
+ </screen>
+ </example>
+ </section>
+
+ <section role="seealso">
+ &reftitle.seealso;
+ <simplelist>
+ <member><methodname>Io\Poll\Context::add</methodname></member>
+ <member><methodname>Io\Poll\Watcher::hasTriggered</methodname></member>
+ <member><enumname>Io\Poll\Backend</enumname></member>
+ </simplelist>
+ </section>
+ </partintro>
+
+</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
+-->
diff --git a/reference/io/io.poll.handle.xml b/reference/io/io.poll.handle.xml
new file mode 100644
index 000000000000..47ec595f46db
--- /dev/null
+++ b/reference/io/io.poll.handle.xml
@@ -0,0 +1,56 @@
+<?xml version="1.0" encoding="utf-8"?>
+<reference xml:id="class.io-poll-handle" 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 Io\Poll\Handle interface</title>
+ <titleabbrev>Io\Poll\Handle</titleabbrev>
+
+ <partintro>
+ <section xml:id="io-poll-handle.intro">
+ &reftitle.intro;
+ <simpara>
+ Represents something an <classname>Io\Poll\Context</classname> can watch.
+ The interface has no methods and only identifies the objects accepted by
+ <methodname>Io\Poll\Context::add</methodname>.
+ </simpara>
+ <simpara>
+ It cannot be implemented by userland classes; attempting to do so is a
+ fatal error.
+ <classname>StreamPollHandle</classname> is the implementation for streams.
+ </simpara>
+ </section>
+
+ <section xml:id="io-poll-handle.synopsis">
+ &reftitle.interfacesynopsis;
+
+ <packagesynopsis>
+ <package>Io\Poll</package>
+
+ <classsynopsis class="interface">
+ <oointerface>
+ <interfacename>Handle</interfacename>
+ </oointerface>
+ </classsynopsis>
+ </packagesynopsis>
+ </section>
+ </partintro>
+
+</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
+-->
diff --git a/reference/io/io/poll/backend/getavailablebackends.xml
b/reference/io/io/poll/backend/getavailablebackends.xml
new file mode 100644
index 000000000000..e1a0eb7ba2e5
--- /dev/null
+++ b/reference/io/io/poll/backend/getavailablebackends.xml
@@ -0,0 +1,85 @@
+<?xml version="1.0" encoding="utf-8"?>
+<refentry xml:id="io-poll-backend.getavailablebackends" xmlns="http://docbook.org/ns/docbook"
xmlns:xlink="http://www.w3.org/1999/xlink">
+ <refnamediv>
+ <refname>Io\Poll\Backend::getAvailableBackends</refname>
+ <refpurpose>Returns the backends available on the platform</refpurpose>
+ </refnamediv>
+
+ <refsect1 role="description">
+ &reftitle.description;
+ <methodsynopsis role="Io\\Poll\\Backend">
+ <modifier>public</modifier> <modifier>static</modifier>
<type>array</type><methodname>Io\Poll\Backend::getAvailableBackends</methodname>
+ <void/>
+ </methodsynopsis>
+ <simpara>
+ Returns the backends an <classname>Io\Poll\Context</classname> can be
+ created with on the current platform.
+ </simpara>
+ </refsect1>
+
+ <refsect1 role="parameters">
+ &reftitle.parameters;
+ &no.function.parameters;
+ </refsect1>
+
+ <refsect1 role="returnvalues">
+ &reftitle.returnvalues;
+ <simpara>
+ Returns a list of <enumname>Io\Poll\Backend</enumname> cases.
+ <constant>Io\Poll\Backend::Auto</constant> is never part of it.
+ </simpara>
+ </refsect1>
+
+ <refsect1 role="examples">
+ &reftitle.examples;
+ <example xml:id="io-poll-backend.getavailablebackends.example.basic">
+ <title><methodname>Io\Poll\Backend::getAvailableBackends</methodname>
example</title>
+ <programlisting role="php">
+<![CDATA[
+<?php
+use Io\Poll\Backend;
+
+foreach (Backend::getAvailableBackends() as $backend) {
+ echo $backend->name, PHP_EOL;
+}
+]]>
+ </programlisting>
+ &example.outputs.similar;
+ <screen>
+<![CDATA[
+Poll
+Epoll
+]]>
+ </screen>
+ </example>
+ </refsect1>
+
+ <refsect1 role="seealso">
+ &reftitle.seealso;
+ <simplelist>
+ <member><methodname>Io\Poll\Backend::isAvailable</methodname></member>
+ <member><methodname>Io\Poll\Context::__construct</methodname></member>
+ </simplelist>
+ </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
+-->
diff --git a/reference/io/io/poll/backend/isavailable.xml
b/reference/io/io/poll/backend/isavailable.xml
new file mode 100644
index 000000000000..09726b5df6af
--- /dev/null
+++ b/reference/io/io/poll/backend/isavailable.xml
@@ -0,0 +1,86 @@
+<?xml version="1.0" encoding="utf-8"?>
+<refentry xml:id="io-poll-backend.isavailable" xmlns="http://docbook.org/ns/docbook"
xmlns:xlink="http://www.w3.org/1999/xlink">
+ <refnamediv>
+ <refname>Io\Poll\Backend::isAvailable</refname>
+ <refpurpose>Checks whether the backend is available on the platform</refpurpose>
+ </refnamediv>
+
+ <refsect1 role="description">
+ &reftitle.description;
+ <methodsynopsis role="Io\\Poll\\Backend">
+ <modifier>public</modifier>
<type>bool</type><methodname>Io\Poll\Backend::isAvailable</methodname>
+ <void/>
+ </methodsynopsis>
+ <simpara>
+ Checks whether an <classname>Io\Poll\Context</classname> can be created
+ with this backend on the current platform.
+ </simpara>
+ </refsect1>
+
+ <refsect1 role="parameters">
+ &reftitle.parameters;
+ &no.function.parameters;
+ </refsect1>
+
+ <refsect1 role="returnvalues">
+ &reftitle.returnvalues;
+ <simpara>
+ Returns &true; if the backend is available, &false; otherwise.
+ <constant>Io\Poll\Backend::Auto</constant> is always available.
+ </simpara>
+ </refsect1>
+
+ <refsect1 role="examples">
+ &reftitle.examples;
+ <example xml:id="io-poll-backend.isavailable.example.basic">
+ <title>Selecting a backend only if it is available</title>
+ <programlisting role="php">
+<![CDATA[
+<?php
+use Io\Poll\Backend;
+use Io\Poll\Context;
+
+$backend = Backend::Kqueue->isAvailable() ? Backend::Kqueue : Backend::Auto;
+$context = new Context($backend);
+
+var_dump(Backend::Auto->isAvailable());
+]]>
+ </programlisting>
+ &example.outputs;
+ <screen>
+<![CDATA[
+bool(true)
+]]>
+ </screen>
+ </example>
+ </refsect1>
+
+ <refsect1 role="seealso">
+ &reftitle.seealso;
+ <simplelist>
+
<member><methodname>Io\Poll\Backend::getAvailableBackends</methodname></member>
+ <member><methodname>Io\Poll\Context::__construct</methodname></member>
+ </simplelist>
+ </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
+-->
diff --git a/reference/io/io/poll/backend/supportsedgetriggering.xml
b/reference/io/io/poll/backend/supportsedgetriggering.xml
new file mode 100644
index 000000000000..8e1a73a42a91
--- /dev/null
+++ b/reference/io/io/poll/backend/supportsedgetriggering.xml
@@ -0,0 +1,102 @@
+<?xml version="1.0" encoding="utf-8"?>
+<refentry xml:id="io-poll-backend.supportsedgetriggering" xmlns="http://docbook.org/ns/docbook"
xmlns:xlink="http://www.w3.org/1999/xlink">
+ <refnamediv>
+ <refname>Io\Poll\Backend::supportsEdgeTriggering</refname>
+ <refpurpose>Checks whether the backend supports edge-triggered events</refpurpose>
+ </refnamediv>
+
+ <refsect1 role="description">
+ &reftitle.description;
+ <methodsynopsis role="Io\\Poll\\Backend">
+ <modifier>public</modifier>
<type>bool</type><methodname>Io\Poll\Backend::supportsEdgeTriggering</methodname>
+ <void/>
+ </methodsynopsis>
+ <simpara>
+ Checks whether <constant>Io\Poll\Event::EdgeTriggered</constant> can be
+ used with this backend.
+ Only <constant>Io\Poll\Backend::Epoll</constant> and
+ <constant>Io\Poll\Backend::Kqueue</constant> support it.
+ </simpara>
+ </refsect1>
+
+ <refsect1 role="parameters">
+ &reftitle.parameters;
+ &no.function.parameters;
+ </refsect1>
+
+ <refsect1 role="returnvalues">
+ &reftitle.returnvalues;
+ <simpara>
+ Returns &true; if the backend supports edge triggering, &false; if it does
+ not or if it is not available on the platform.
+ For <constant>Io\Poll\Backend::Auto</constant>, the result is that of the
+ backend it selects.
+ </simpara>
+ </refsect1>
+
+ <refsect1 role="examples">
+ &reftitle.examples;
+ <example xml:id="io-poll-backend.supportsedgetriggering.example.basic">
+ <title>Requesting edge triggering only when it is supported</title>
+ <programlisting role="php">
+<![CDATA[
+<?php
+use Io\Poll\Context;
+use Io\Poll\Event;
+
+[$reader, $writer] = stream_socket_pair(STREAM_PF_UNIX, STREAM_SOCK_STREAM, STREAM_IPPROTO_IP);
+
+$context = new Context();
+
+$events = [Event::Read];
+if ($context->getBackend()->supportsEdgeTriggering()) {
+ $events[] = Event::EdgeTriggered;
+}
+
+$watcher = $context->add(new StreamPollHandle($reader), $events);
+var_dump($watcher->getWatchedEvents());
+]]>
+ </programlisting>
+ &example.outputs.similar;
+ <screen>
+<![CDATA[
+array(2) {
+ [0]=>
+ enum(Io\Poll\Event::Read)
+ [1]=>
+ enum(Io\Poll\Event::EdgeTriggered)
+}
+]]>
+ </screen>
+ </example>
+ </refsect1>
+
+ <refsect1 role="seealso">
+ &reftitle.seealso;
+ <simplelist>
+ <member><enumname>Io\Poll\Event</enumname></member>
+ <member><methodname>Io\Poll\Context::getBackend</methodname></member>
+ </simplelist>
+ </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
+-->
diff --git a/reference/io/io/poll/context/add.xml b/reference/io/io/poll/context/add.xml
new file mode 100644
index 000000000000..01f1cee23188
--- /dev/null
+++ b/reference/io/io/poll/context/add.xml
@@ -0,0 +1,178 @@
+<?xml version="1.0" encoding="utf-8"?>
+<refentry xml:id="io-poll-context.add" xmlns="http://docbook.org/ns/docbook"
xmlns:xlink="http://www.w3.org/1999/xlink">
+ <refnamediv>
+ <refname>Io\Poll\Context::add</refname>
+ <refpurpose>Starts watching a handle</refpurpose>
+ </refnamediv>
+
+ <refsect1 role="description">
+ &reftitle.description;
+ <methodsynopsis role="Io\\Poll\\Context">
+ <modifier>public</modifier>
<type>Io\Poll\Watcher</type><methodname>Io\Poll\Context::add</methodname>
+
<methodparam><type>Io\Poll\Handle</type><parameter>handle</parameter></methodparam>
+
<methodparam><type>array</type><parameter>events</parameter></methodparam>
+ <methodparam
choice="opt"><type>mixed</type><parameter>data</parameter><initializer>&null;</initializer></methodparam>
+ </methodsynopsis>
+ <simpara>
+ Registers <parameter>handle</parameter> with the context, so that
+ <methodname>Io\Poll\Context::wait</methodname> reports it when one of the
+ given <parameter>events</parameter> occurs.
+ </simpara>
+ <simpara>
+ A handle can be watched only once by a context.
+ Two <classname>StreamPollHandle</classname> objects created from the same
+ stream count as the same handle.
+ </simpara>
+ <simpara>
+ The context keeps the returned <classname>Io\Poll\Watcher</classname> alive
+ until it is removed with <methodname>Io\Poll\Watcher::remove</methodname>,
+ its stream is closed, or the context is destroyed.
+ </simpara>
+ </refsect1>
+
+ <refsect1 role="parameters">
+ &reftitle.parameters;
+ <variablelist>
+ <varlistentry>
+ <term><parameter>handle</parameter></term>
+ <listitem>
+ <simpara>
+ The handle to watch.
+ If it is a <classname>StreamPollHandle</classname> whose stream is not
+ backed by a file descriptor, an <constant>E_WARNING</constant> is
+ emitted in addition to the exception.
+ </simpara>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
+ <term><parameter>events</parameter></term>
+ <listitem>
+ <simpara>
+ A non-empty list of <enumname>Io\Poll\Event</enumname> cases.
+ It combines the conditions to watch for, such as
+ <constant>Io\Poll\Event::Read</constant> and
+ <constant>Io\Poll\Event::Write</constant>, with the
+ <constant>Io\Poll\Event::OneShot</constant> and
+ <constant>Io\Poll\Event::EdgeTriggered</constant> modifiers.
+ </simpara>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
+ <term><parameter>data</parameter></term>
+ <listitem>
+ <simpara>
+ An arbitrary value to associate with the watcher, for example a callback
+ or an object describing the connection.
+ It is returned by <methodname>Io\Poll\Watcher::getData</methodname>.
+ </simpara>
+ </listitem>
+ </varlistentry>
+ </variablelist>
+ </refsect1>
+
+ <refsect1 role="returnvalues">
+ &reftitle.returnvalues;
+ <simpara>
+ Returns the <classname>Io\Poll\Watcher</classname> that represents the
+ registration.
+ </simpara>
+ </refsect1>
+
+ <refsect1 role="errors">
+ &reftitle.errors;
+ <simpara>
+ Throws a <exceptionname>TypeError</exceptionname> if
+ <parameter>events</parameter> is empty or contains a value that is not an
+ <enumname>Io\Poll\Event</enumname> case.
+ </simpara>
+ <simpara>
+ Throws an <exceptionname>Io\Poll\InvalidHandleException</exceptionname> if
+ <parameter>handle</parameter> cannot be polled, for example because its
+ stream was closed or is not backed by a file descriptor.
+ </simpara>
+ <simpara>
+ Throws an
+ <exceptionname>Io\Poll\HandleAlreadyWatchedException</exceptionname> if
+ <parameter>handle</parameter> is already watched by this context.
+ </simpara>
+ <simpara>
+ Throws an <exceptionname>Io\Poll\FailedHandleAddException</exceptionname>
+ if the backend rejects the registration, for example when a regular file is
+ added to a context that uses <constant>Io\Poll\Backend::Epoll</constant>,
+ or when <constant>Io\Poll\Event::EdgeTriggered</constant> is requested from
+ <constant>Io\Poll\Backend::Poll</constant>.
+ </simpara>
+ </refsect1>
+
+ <refsect1 role="examples">
+ &reftitle.examples;
+ <example xml:id="io-poll-context.add.example.basic">
+ <title><methodname>Io\Poll\Context::add</methodname> example</title>
+ <programlisting role="php">
+<![CDATA[
+<?php
+use Io\Poll\Context;
+use Io\Poll\Event;
+use Io\Poll\HandleAlreadyWatchedException;
+
+[$reader, $writer] = stream_socket_pair(STREAM_PF_UNIX, STREAM_SOCK_STREAM, STREAM_IPPROTO_IP);
+
+$context = new Context();
+$handle = new StreamPollHandle($reader);
+
+$watcher = $context->add($handle, [Event::Read], ['name' => 'reader']);
+var_dump($watcher->isActive());
+var_dump($watcher->getData());
+
+try {
+ $context->add($handle, [Event::Write]);
+} catch (HandleAlreadyWatchedException $exception) {
+ echo $exception->getMessage(), PHP_EOL;
+}
+]]>
+ </programlisting>
+ &example.outputs;
+ <screen>
+<![CDATA[
+bool(true)
+array(1) {
+ ["name"]=>
+ string(6) "reader"
+}
+Handle already added
+]]>
+ </screen>
+ </example>
+ </refsect1>
+
+ <refsect1 role="seealso">
+ &reftitle.seealso;
+ <simplelist>
+ <member><methodname>Io\Poll\Context::wait</methodname></member>
+ <member><methodname>Io\Poll\Watcher::modify</methodname></member>
+ <member><methodname>Io\Poll\Watcher::remove</methodname></member>
+ <member><classname>StreamPollHandle</classname></member>
+ </simplelist>
+ </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
+-->
diff --git a/reference/io/io/poll/context/construct.xml b/reference/io/io/poll/context/construct.xml
new file mode 100644
index 000000000000..73c690d5e57e
--- /dev/null
+++ b/reference/io/io/poll/context/construct.xml
@@ -0,0 +1,112 @@
+<?xml version="1.0" encoding="utf-8"?>
+<refentry xml:id="io-poll-context.construct" xmlns="http://docbook.org/ns/docbook"
xmlns:xlink="http://www.w3.org/1999/xlink">
+ <refnamediv>
+ <refname>Io\Poll\Context::__construct</refname>
+ <refpurpose>Creates a polling context</refpurpose>
+ </refnamediv>
+
+ <refsect1 role="description">
+ &reftitle.description;
+ <constructorsynopsis role="Io\\Poll\\Context">
+ <modifier>public</modifier>
<methodname>Io\Poll\Context::__construct</methodname>
+ <methodparam
choice="opt"><type>Io\Poll\Backend</type><parameter>backend</parameter><initializer><constant>Io\Poll\Backend::Auto</constant></initializer></methodparam>
+ </constructorsynopsis>
+ <simpara>
+ Creates a polling context that uses the given
+ <parameter>backend</parameter>.
+ </simpara>
+ </refsect1>
+
+ <refsect1 role="parameters">
+ &reftitle.parameters;
+ <variablelist>
+ <varlistentry>
+ <term><parameter>backend</parameter></term>
+ <listitem>
+ <simpara>
+ The polling mechanism to use.
+ With <constant>Io\Poll\Backend::Auto</constant>, the most suitable
+ backend available on the platform is selected;
+ <methodname>Io\Poll\Context::getBackend</methodname> tells which one it
+ is.
+ </simpara>
+ </listitem>
+ </varlistentry>
+ </variablelist>
+ </refsect1>
+
+ <refsect1 role="errors">
+ &reftitle.errors;
+ <simpara>
+ Throws an
+ <exceptionname>Io\Poll\BackendUnavailableException</exceptionname> if
+ <parameter>backend</parameter> is not available on the platform.
+ </simpara>
+ <simpara>
+ Throws an
+ <exceptionname>Io\Poll\FailedContextInitializationException</exceptionname>
+ if the backend cannot be initialized.
+ </simpara>
+ </refsect1>
+
+ <refsect1 role="examples">
+ &reftitle.examples;
+ <example xml:id="io-poll-context.construct.example.basic">
+ <title><methodname>Io\Poll\Context::__construct</methodname>
example</title>
+ <programlisting role="php">
+<![CDATA[
+<?php
+use Io\Poll\Backend;
+use Io\Poll\BackendUnavailableException;
+use Io\Poll\Context;
+
+$context = new Context();
+var_dump($context->getBackend());
+
+try {
+ $context = new Context(Backend::WSAPoll);
+} catch (BackendUnavailableException $exception) {
+ echo $exception->getMessage(), PHP_EOL;
+}
+]]>
+ </programlisting>
+ &example.outputs.similar;
+ <screen>
+<![CDATA[
+enum(Io\Poll\Backend::Epoll)
+Backend WSAPoll not available
+]]>
+ </screen>
+ </example>
+ </refsect1>
+
+ <refsect1 role="seealso">
+ &reftitle.seealso;
+ <simplelist>
+ <member><methodname>Io\Poll\Context::getBackend</methodname></member>
+
<member><methodname>Io\Poll\Backend::getAvailableBackends</methodname></member>
+ <member><methodname>Io\Poll\Backend::isAvailable</methodname></member>
+ </simplelist>
+ </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
+-->
diff --git a/reference/io/io/poll/context/getbackend.xml
b/reference/io/io/poll/context/getbackend.xml
new file mode 100644
index 000000000000..a39111a9d265
--- /dev/null
+++ b/reference/io/io/poll/context/getbackend.xml
@@ -0,0 +1,89 @@
+<?xml version="1.0" encoding="utf-8"?>
+<refentry xml:id="io-poll-context.getbackend" xmlns="http://docbook.org/ns/docbook"
xmlns:xlink="http://www.w3.org/1999/xlink">
+ <refnamediv>
+ <refname>Io\Poll\Context::getBackend</refname>
+ <refpurpose>Returns the backend used by the context</refpurpose>
+ </refnamediv>
+
+ <refsect1 role="description">
+ &reftitle.description;
+ <methodsynopsis role="Io\\Poll\\Context">
+ <modifier>public</modifier>
<type>Io\Poll\Backend</type><methodname>Io\Poll\Context::getBackend</methodname>
+ <void/>
+ </methodsynopsis>
+ <simpara>
+ Returns the backend that the context polls with.
+ This is never <constant>Io\Poll\Backend::Auto</constant>: a context created
+ with it reports the backend that was selected.
+ </simpara>
+ </refsect1>
+
+ <refsect1 role="parameters">
+ &reftitle.parameters;
+ &no.function.parameters;
+ </refsect1>
+
+ <refsect1 role="returnvalues">
+ &reftitle.returnvalues;
+ <simpara>
+ Returns the <enumname>Io\Poll\Backend</enumname> case of the backend in
+ use.
+ </simpara>
+ </refsect1>
+
+ <refsect1 role="examples">
+ &reftitle.examples;
+ <example xml:id="io-poll-context.getbackend.example.basic">
+ <title><methodname>Io\Poll\Context::getBackend</methodname>
example</title>
+ <programlisting role="php">
+<![CDATA[
+<?php
+use Io\Poll\Backend;
+use Io\Poll\Context;
+
+$context = new Context();
+var_dump($context->getBackend());
+
+$context = new Context(Backend::Poll);
+var_dump($context->getBackend());
+]]>
+ </programlisting>
+ &example.outputs.similar;
+ <screen>
+<![CDATA[
+enum(Io\Poll\Backend::Epoll)
+enum(Io\Poll\Backend::Poll)
+]]>
+ </screen>
+ </example>
+ </refsect1>
+
+ <refsect1 role="seealso">
+ &reftitle.seealso;
+ <simplelist>
+ <member><methodname>Io\Poll\Context::__construct</methodname></member>
+
<member><methodname>Io\Poll\Backend::supportsEdgeTriggering</methodname></member>
+ </simplelist>
+ </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
+-->
diff --git a/reference/io/io/poll/context/wait.xml b/reference/io/io/poll/context/wait.xml
new file mode 100644
index 000000000000..787efef46dd7
--- /dev/null
+++ b/reference/io/io/poll/context/wait.xml
@@ -0,0 +1,160 @@
+<?xml version="1.0" encoding="utf-8"?>
+<refentry xml:id="io-poll-context.wait" xmlns="http://docbook.org/ns/docbook"
xmlns:xlink="http://www.w3.org/1999/xlink">
+ <refnamediv>
+ <refname>Io\Poll\Context::wait</refname>
+ <refpurpose>Waits for events on the watched handles</refpurpose>
+ </refnamediv>
+
+ <refsect1 role="description">
+ &reftitle.description;
+ <methodsynopsis role="Io\\Poll\\Context">
+ <modifier>public</modifier>
<type>array</type><methodname>Io\Poll\Context::wait</methodname>
+ <methodparam choice="opt"><type
class="union"><type>Time\Duration</type><type>null</type></type><parameter>timeout</parameter><initializer>&null;</initializer></methodparam>
+ <methodparam choice="opt"><type
class="union"><type>int</type><type>null</type></type><parameter>maxEvents</parameter><initializer>&null;</initializer></methodparam>
+ </methodsynopsis>
+ <simpara>
+ Blocks until at least one watched handle is ready or the
+ <parameter>timeout</parameter> expires, and returns the watchers whose
+ events were triggered.
+ </simpara>
+ <simpara>
+ Unless <constant>Io\Poll\Event::EdgeTriggered</constant> or
+ <constant>Io\Poll\Event::OneShot</constant> is used, a watcher is returned
+ by every call for as long as its condition holds, for example until the
+ pending data has been read.
+ Such a watcher for <constant>Io\Poll\Event::Read</constant> on a stream is
+ also returned while unread data remains in the read buffer of the stream.
+ </simpara>
+ <simpara>
+ If the context has no active watcher, the call returns an empty &array;
+ once the <parameter>timeout</parameter> expires. Without a
+ <parameter>timeout</parameter> the behavior depends on the backend: the
+ call either returns immediately or blocks indefinitely, so it should not
+ be relied upon.
+ </simpara>
+ </refsect1>
+
+ <refsect1 role="parameters">
+ &reftitle.parameters;
+ <variablelist>
+ <varlistentry>
+ <term><parameter>timeout</parameter></term>
+ <listitem>
+ <simpara>
+ The maximum time to wait.
+ A zero duration makes the method return immediately, and &null; waits
+ without a time limit.
+ </simpara>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
+ <term><parameter>maxEvents</parameter></term>
+ <listitem>
+ <simpara>
+ The maximum number of watchers to return in one call.
+ With &null;, the backend chooses a value based on the number of watched
+ handles.
+ The other watchers that are ready are not returned by this call.
+ </simpara>
+ </listitem>
+ </varlistentry>
+ </variablelist>
+ </refsect1>
+
+ <refsect1 role="returnvalues">
+ &reftitle.returnvalues;
+ <simpara>
+ Returns a list of the <classname>Io\Poll\Watcher</classname> objects that
+ were triggered, or an empty &array; if none was.
+ The events of each watcher are available from
+ <methodname>Io\Poll\Watcher::getTriggeredEvents</methodname> and
+ <methodname>Io\Poll\Watcher::hasTriggered</methodname>.
+ </simpara>
+ </refsect1>
+
+ <refsect1 role="errors">
+ &reftitle.errors;
+ <simpara>
+ Throws a <exceptionname>ValueError</exceptionname> if
+ <parameter>timeout</parameter> is negative.
+ </simpara>
+ <simpara>
+ Throws a <exceptionname>ValueError</exceptionname> if
+ <parameter>maxEvents</parameter> is less than <literal>1</literal> or
+ greater than <literal>2147483647</literal>.
+ </simpara>
+ <simpara>
+ Throws an <exceptionname>Io\Poll\FailedPollWaitException</exceptionname> if
+ the backend fails to wait for events.
+ </simpara>
+ </refsect1>
+
+ <refsect1 role="examples">
+ &reftitle.examples;
+ <example xml:id="io-poll-context.wait.example.basic">
+ <title><methodname>Io\Poll\Context::wait</methodname> example</title>
+ <programlisting role="php">
+<![CDATA[
+<?php
+use Io\Poll\Context;
+use Io\Poll\Event;
+use Time\Duration;
+
+[$reader, $writer] = stream_socket_pair(STREAM_PF_UNIX, STREAM_SOCK_STREAM, STREAM_IPPROTO_IP);
+
+$context = new Context();
+$context->add(new StreamPollHandle($reader), [Event::Read], 'reader');
+$context->add(new StreamPollHandle($writer), [Event::Write], 'writer');
+
+// Only the writing end is ready.
+foreach ($context->wait(Duration::fromMilliseconds(100)) as $watcher) {
+ echo $watcher->getData(), PHP_EOL;
+}
+
+fwrite($writer, 'ping');
+
+// Both ends are ready, but at most one watcher is returned.
+var_dump(count($context->wait(Duration::fromMilliseconds(100), 1)));
+]]>
+ </programlisting>
+ &example.outputs;
+ <screen>
+<![CDATA[
+writer
+int(1)
+]]>
+ </screen>
+ </example>
+ </refsect1>
+
+ <refsect1 role="seealso">
+ &reftitle.seealso;
+ <simplelist>
+ <member><methodname>Io\Poll\Context::add</methodname></member>
+
<member><methodname>Io\Poll\Watcher::getTriggeredEvents</methodname></member>
+ <member><classname>Time\Duration</classname></member>
+ <member><function>stream_select</function></member>
+ </simplelist>
+ </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
+-->
diff --git a/reference/io/streampollhandle.xml b/reference/io/streampollhandle.xml
new file mode 100644
index 000000000000..c3ec8e41a282
--- /dev/null
+++ b/reference/io/streampollhandle.xml
@@ -0,0 +1,68 @@
+<?xml version="1.0" encoding="utf-8"?>
+<reference xml:id="class.streampollhandle" 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 StreamPollHandle class</title>
+ <titleabbrev>StreamPollHandle</titleabbrev>
+
+ <partintro>
+ <section xml:id="streampollhandle.intro">
+ &reftitle.intro;
+ <simpara>
+ An <classname>Io\Poll\Handle</classname> that allows a stream to be
+ watched by an <classname>Io\Poll\Context</classname>.
+ </simpara>
+ <simpara>
+ Only streams that are backed by a file descriptor of the operating system
+ can be polled, such as sockets and pipes.
+ Which kinds of streams are accepted depends on the backend: for example,
+ <constant>Io\Poll\Backend::WSAPoll</constant> only accepts sockets, and
+ <constant>Io\Poll\Backend::Epoll</constant> rejects regular files.
+ </simpara>
+ <simpara>
+ Objects of this class cannot be cloned or serialized.
+ </simpara>
+ </section>
+
+ <section xml:id="streampollhandle.synopsis">
+ &reftitle.classsynopsis;
+
+ <classsynopsis class="class">
+ <ooclass>
+ <modifier>final</modifier>
+ <classname>StreamPollHandle</classname>
+ </ooclass>
+
+ <oointerface>
+ <modifier>implements</modifier>
+ <interfacename>Io\Poll\Handle</interfacename>
+ </oointerface>
+
+ <classsynopsisinfo role="comment">&Methods;</classsynopsisinfo>
+ <xi:include xpointer="xmlns(db=http://docbook.org/ns/docbook)
xpointer(id('class.streampollhandle')/db:refentry/db:refsect1[@role='description']/descendant::db:constructorsynopsis[@role='StreamPollHandle'])"/>
+ <xi:include xpointer="xmlns(db=http://docbook.org/ns/docbook)
xpointer(id('class.streampollhandle')/db:refentry/db:refsect1[@role='description']/descendant::db:methodsynopsis[@role='StreamPollHandle'])"/>
+ </classsynopsis>
+ </section>
+ </partintro>
+
+ &reference.io.entities.streampollhandle;
+
+</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
+-->
diff --git a/reference/io/streampollhandle/construct.xml
b/reference/io/streampollhandle/construct.xml
new file mode 100644
index 000000000000..0a66bbc57784
--- /dev/null
+++ b/reference/io/streampollhandle/construct.xml
@@ -0,0 +1,102 @@
+<?xml version="1.0" encoding="utf-8"?>
+<refentry xml:id="streampollhandle.construct" xmlns="http://docbook.org/ns/docbook"
xmlns:xlink="http://www.w3.org/1999/xlink">
+ <refnamediv>
+ <refname>StreamPollHandle::__construct</refname>
+ <refpurpose>Creates a poll handle for a stream</refpurpose>
+ </refnamediv>
+
+ <refsect1 role="description">
+ &reftitle.description;
+ <constructorsynopsis role="StreamPollHandle">
+ <modifier>public</modifier>
<methodname>StreamPollHandle::__construct</methodname>
+
<methodparam><type>resource</type><parameter>stream</parameter></methodparam>
+ </constructorsynopsis>
+ <simpara>
+ Creates a handle that allows <parameter>stream</parameter> to be watched by
+ an <classname>Io\Poll\Context</classname>.
+ The handle holds a reference to the stream, which therefore stays open
+ until <function>fclose</function> is called on it.
+ </simpara>
+ </refsect1>
+
+ <refsect1 role="parameters">
+ &reftitle.parameters;
+ <variablelist>
+ <varlistentry>
+ <term><parameter>stream</parameter></term>
+ <listitem>
+ <simpara>
+ An open stream, such as a socket created with
+ <function>stream_socket_client</function> or
+ <function>stream_socket_accept</function>.
+ </simpara>
+ </listitem>
+ </varlistentry>
+ </variablelist>
+ </refsect1>
+
+ <refsect1 role="errors">
+ &reftitle.errors;
+ <simpara>
+ Throws a <exceptionname>TypeError</exceptionname> if
+ <parameter>stream</parameter> is not an open stream.
+ </simpara>
+ </refsect1>
+
+ <refsect1 role="examples">
+ &reftitle.examples;
+ <example xml:id="streampollhandle.construct.example.basic">
+ <title><methodname>StreamPollHandle::__construct</methodname>
example</title>
+ <programlisting role="php">
+<![CDATA[
+<?php
+use Io\Poll\Context;
+use Io\Poll\Event;
+
+[$reader, $writer] = stream_socket_pair(STREAM_PF_UNIX, STREAM_SOCK_STREAM, STREAM_IPPROTO_IP);
+
+$handle = new StreamPollHandle($reader);
+
+$context = new Context();
+$watcher = $context->add($handle, [Event::Read]);
+var_dump($watcher->isActive());
+]]>
+ </programlisting>
+ &example.outputs;
+ <screen>
+<![CDATA[
+bool(true)
+]]>
+ </screen>
+ </example>
+ </refsect1>
+
+ <refsect1 role="seealso">
+ &reftitle.seealso;
+ <simplelist>
+ <member><methodname>Io\Poll\Context::add</methodname></member>
+ <member><methodname>StreamPollHandle::getStream</methodname></member>
+ </simplelist>
+ </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
+-->
diff --git a/reference/io/streampollhandle/getstream.xml
b/reference/io/streampollhandle/getstream.xml
new file mode 100644
index 000000000000..be8e6ef8e205
--- /dev/null
+++ b/reference/io/streampollhandle/getstream.xml
@@ -0,0 +1,88 @@
+<?xml version="1.0" encoding="utf-8"?>
+<refentry xml:id="streampollhandle.getstream" xmlns="http://docbook.org/ns/docbook"
xmlns:xlink="http://www.w3.org/1999/xlink">
+ <refnamediv>
+ <refname>StreamPollHandle::getStream</refname>
+ <refpurpose>Returns the stream of the handle</refpurpose>
+ </refnamediv>
+
+ <refsect1 role="description">
+ &reftitle.description;
+ <methodsynopsis role="StreamPollHandle">
+ <modifier>public</modifier>
<type>resource</type><methodname>StreamPollHandle::getStream</methodname>
+ <void/>
+ </methodsynopsis>
+ <simpara>
+ Returns the stream that was passed to
+ <methodname>StreamPollHandle::__construct</methodname>.
+ </simpara>
+ </refsect1>
+
+ <refsect1 role="parameters">
+ &reftitle.parameters;
+ &no.function.parameters;
+ </refsect1>
+
+ <refsect1 role="returnvalues">
+ &reftitle.returnvalues;
+ <simpara>
+ Returns the stream &resource;.
+ If the stream was closed in the meantime, the returned value is a closed
+ resource.
+ </simpara>
+ </refsect1>
+
+ <refsect1 role="examples">
+ &reftitle.examples;
+ <example xml:id="streampollhandle.getstream.example.basic">
+ <title><methodname>StreamPollHandle::getStream</methodname>
example</title>
+ <programlisting role="php">
+<![CDATA[
+<?php
+[$reader, $writer] = stream_socket_pair(STREAM_PF_UNIX, STREAM_SOCK_STREAM, STREAM_IPPROTO_IP);
+
+$handle = new StreamPollHandle($reader);
+var_dump($handle->getStream() === $reader);
+
+fclose($reader);
+var_dump(is_resource($handle->getStream()));
+]]>
+ </programlisting>
+ &example.outputs;
+ <screen>
+<![CDATA[
+bool(true)
+bool(false)
+]]>
+ </screen>
+ </example>
+ </refsect1>
+
+ <refsect1 role="seealso">
+ &reftitle.seealso;
+ <simplelist>
+ <member><methodname>Io\Poll\Watcher::getHandle</methodname></member>
+ <member><methodname>StreamPollHandle::isValid</methodname></member>
+ </simplelist>
+ </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
+-->
diff --git a/reference/io/streampollhandle/isvalid.xml b/reference/io/streampollhandle/isvalid.xml
new file mode 100644
index 000000000000..35fb50dcfcba
--- /dev/null
+++ b/reference/io/streampollhandle/isvalid.xml
@@ -0,0 +1,92 @@
+<?xml version="1.0" encoding="utf-8"?>
+<refentry xml:id="streampollhandle.isvalid" xmlns="http://docbook.org/ns/docbook"
xmlns:xlink="http://www.w3.org/1999/xlink">
+ <refnamediv>
+ <refname>StreamPollHandle::isValid</refname>
+ <refpurpose>Checks whether the stream is open and not at end-of-file</refpurpose>
+ </refnamediv>
+
+ <refsect1 role="description">
+ &reftitle.description;
+ <methodsynopsis role="StreamPollHandle">
+ <modifier>public</modifier>
<type>bool</type><methodname>StreamPollHandle::isValid</methodname>
+ <void/>
+ </methodsynopsis>
+ <simpara>
+ Checks whether the stream of the handle is still open and has not reached
+ its end.
+ </simpara>
+ </refsect1>
+
+ <refsect1 role="parameters">
+ &reftitle.parameters;
+ &no.function.parameters;
+ </refsect1>
+
+ <refsect1 role="returnvalues">
+ &reftitle.returnvalues;
+ <simpara>
+ Returns &true; if the stream is open and not at end-of-file, &false;
+ otherwise.
+ </simpara>
+ </refsect1>
+
+ <refsect1 role="examples">
+ &reftitle.examples;
+ <example xml:id="streampollhandle.isvalid.example.basic">
+ <title><methodname>StreamPollHandle::isValid</methodname>
example</title>
+ <programlisting role="php">
+<![CDATA[
+<?php
+[$reader, $writer] = stream_socket_pair(STREAM_PF_UNIX, STREAM_SOCK_STREAM, STREAM_IPPROTO_IP);
+
+$handle = new StreamPollHandle($reader);
+var_dump($handle->isValid());
+
+// The other end is closed, so the stream reaches its end.
+fclose($writer);
+var_dump($handle->isValid());
+
+fclose($reader);
+var_dump($handle->isValid());
+]]>
+ </programlisting>
+ &example.outputs;
+ <screen>
+<![CDATA[
+bool(true)
+bool(false)
+bool(false)
+]]>
+ </screen>
+ </example>
+ </refsect1>
+
+ <refsect1 role="seealso">
+ &reftitle.seealso;
+ <simplelist>
+ <member><methodname>Io\Poll\Watcher::isActive</methodname></member>
+ <member><function>feof</function></member>
+ </simplelist>
+ </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
+-->
diff --git a/reference/io/versions.xml b/reference/io/versions.xml
new file mode 100644
index 000000000000..c68f2646f85d
--- /dev/null
+++ b/reference/io/versions.xml
@@ -0,0 +1,51 @@
+<?xml version="1.0" encoding="utf-8"?>
+<?do-not-translate?>
+
+<versions>
+ <!-- Classes and Methods -->
+
+ <!-- Io\Poll\Context -->
+ <function name='io\poll\context' from='PHP 8 >= 8.6.0'/>
+ <function name='io\poll\context::__construct' from='PHP 8 >=
8.6.0'/>
+ <function name='io\poll\context::add' from='PHP 8 >= 8.6.0'/>
+ <function name='io\poll\context::wait' from='PHP 8 >= 8.6.0'/>
+ <function name='io\poll\context::getbackend' from='PHP 8 >=
8.6.0'/>
+
+ <!-- Io\Poll\Handle -->
+ <function name='io\poll\handle' from='PHP 8 >= 8.6.0'/>
+
+ <!-- StreamPollHandle -->
+ <function name='streampollhandle' from='PHP 8 >= 8.6.0'/>
+ <function name='streampollhandle::__construct' from='PHP 8 >=
8.6.0'/>
+ <function name='streampollhandle::getstream' from='PHP 8 >=
8.6.0'/>
+ <function name='streampollhandle::isvalid' from='PHP 8 >=
8.6.0'/>
+
+ <!-- Io\Poll\Backend -->
+ <function name='io\poll\backend' from='PHP 8 >= 8.6.0'/>
+ <function name='io\poll\backend::getavailablebackends' from='PHP 8 >=
8.6.0'/>
+ <function name='io\poll\backend::isavailable' from='PHP 8 >=
8.6.0'/>
+ <function name='io\poll\backend::supportsedgetriggering' from='PHP 8 >=
8.6.0'/>
+
+ <!-- Io\Poll\Event -->
+ <function name='io\poll\event' from='PHP 8 >= 8.6.0'/>
+</versions>
+<!-- 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
+-->
diff --git a/reference/stream/functions/stream-select.xml
b/reference/stream/functions/stream-select.xml
index 4b7b06d9ea48..fc2e3d16edc3 100644
--- a/reference/stream/functions/stream-select.xml
+++ b/reference/stream/functions/stream-select.xml
@@ -280,6 +280,7 @@ if (false === stream_select($r, $w, $e, 0)) {
<simplelist>
<member><function>stream_set_blocking</function></member>
<member><function>socket_select</function></member>
+ <member><classname>Io\Poll\Context</classname></member>
</simplelist>
</refsect1>
</refentry>