svn: /phpdoc/en/trunk/reference/eio/ examples.xml
| From: | Ruslan Osmanov | Date: | Tue, 10 Nov 2015 08:02:51 +0000 |
| Subject: | svn: /phpdoc/en/trunk/reference/eio/ examples.xml | ||
| Groups: | php.doc.cvs | ||
| Request: | Send a blank email to doc-cvs+get-13833@lists.php.net to get a copy of this message | ||
osmanov Tue, 10 Nov 2015 08:02:51 +0000
Revision: http://svn.php.net/viewvc?view=revision&revision=338100
Log:
Add: eio example using eio with event extension
Changed paths:
U phpdoc/en/trunk/reference/eio/examples.xml
Modified: phpdoc/en/trunk/reference/eio/examples.xml
===================================================================
--- phpdoc/en/trunk/reference/eio/examples.xml 2015-11-10 07:31:35 UTC (rev 338099)
+++ phpdoc/en/trunk/reference/eio/examples.xml 2015-11-10 08:02:51 UTC (rev 338100)
@@ -190,7 +190,7 @@
<para>
<example>
- <title>Using eio with libevent</title>
+ <title>Using eio with libevent extension</title>
<programlisting role="php"><![CDATA[
<?php
function my_eio_poll($fd, $events, $arg) {
@@ -245,6 +245,51 @@
</example>
</para>
+<para>
+ <example>
+ <title>Using eio with event extension</title>
+ <programlisting role="php"><![CDATA[
+<?php
+$base = new EventBase();
+
+// Retrieve eio polling stream.
+// Note, this variable should be alive as long as the event loop is running.
+$eio_stream = eio_get_event_stream();
+
+// Bind eio polling stream to the event loop.
+$poll_event = new Event($base, $eio_stream, Event::READ, function () {
+ if (eio_nreqs()) {
+ eio_poll();
+ }
+});
+$poll_event->add();
+
+// Add eio jobs
+eio_nop(EIO_PRI_DEFAULT, function () {
+ echo "eio_nop\n";
+});
+
+// Add events
+$timer = Event::timer($base, function () {
+ echo "2 seconds elapsed\n";
+});
+$timer->add(2);
+
+// Dispatch events.
+$base->dispatch();
+?>
+]]></programlisting>
+
+&example.outputs.similar;
+<screen>
+ <![CDATA[
+eio_nop
+2 seconds elapsed
+ ]]>
+ </screen>
+</example>
+</para>
+
</chapter>
<!-- Keep this comment at the end of the file