Skip to content

Commit ffe26e9

Browse files
committed
Documentation for common event loop use cases
1 parent 5944b2d commit ffe26e9

File tree

5 files changed

+76
-4
lines changed

5 files changed

+76
-4
lines changed

README.md

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,31 @@ A `stream_select()` based event loop.
158158

159159
This uses the [`stream_select()`](http://php.net/manual/en/function.stream-select.php)
160160
function and is the only implementation which works out of the box with PHP.
161-
It does a simple `select` system call.
162-
It's not the most performant of loops, but still does the job quite well.
161+
162+
This event loop works out of the box on PHP 5.4 through PHP 7+ and HHVM.
163+
This means that no installation is required and this library works on all
164+
platforms and supported PHP versions.
165+
Accordingly, the [`Factory`](#factory) will use this event loop by default if
166+
you do not install any of the event loop extensions listed below.
167+
168+
Under the hood, it does a simple `select` system call.
169+
This system call is limited to the maximum file descriptor number of
170+
`FD_SETSIZE` (platform dependent, commonly 1024) and scales with `O(m)`
171+
(`m` being the maximum file descriptor number passed).
172+
This means that you may run into issues when handling thousands of streams
173+
concurrently and you may want to look into using one of the alternative
174+
event loop implementations listed below in this case.
175+
If your use case is among the many common use cases that involve handling only
176+
dozens or a few hundred streams at once, then this event loop implementation
177+
performs really well.
178+
179+
If you want to use signal handling (see also [`addSignal()`](#addsignal) below),
180+
this event loop implementation requires `ext-pcntl`.
181+
This extension is only available for Unix-like platforms and does not support
182+
Windows.
183+
It is commonly installed as part of many PHP distributions.
184+
If this extension is missing (or you're running on Windows), signal handling is
185+
not supported and throws a `BadMethodCallException` instead.
163186

164187
#### LibEventLoop
165188

@@ -168,20 +191,33 @@ An `ext-libevent` based event loop.
168191
This uses the [`libevent` PECL extension](https://pecl.php.net/package/libevent).
169192
`libevent` itself supports a number of system-specific backends (epoll, kqueue).
170193

194+
This event loop does only work with PHP 5.
195+
An [unofficial update](https://github.com/php/pecl-event-libevent/pull/2) for
196+
PHP 7 does exist, but it is known to cause regular crashes due to `SEGFAULT`s.
197+
To reiterate: Using this event loop on PHP 7 is not recommended.
198+
Accordingly, the [`Factory`](#factory) will not try to use this event loop on
199+
PHP 7.
200+
171201
#### LibEvLoop
172202

173203
An `ext-libev` based event loop.
174204

175205
This uses an [unofficial `libev` extension](https://github.com/m4rw3r/php-libev).
176206
It supports the same backends as libevent.
177207

208+
This loop does only work with PHP 5.
209+
An update for PHP 7 is [unlikely](https://github.com/m4rw3r/php-libev/issues/8)
210+
to happen any time soon.
211+
178212
#### ExtEventLoop
179213

180214
An `ext-event` based event loop.
181215

182216
This uses the [`event` PECL extension](https://pecl.php.net/package/event).
183217
It supports the same backends as libevent.
184218

219+
This loop is known to work with PHP 5.4 through PHP 7+.
220+
185221
### LoopInterface
186222

187223
#### addTimer()

src/ExtEventLoop.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
* This uses the [`event` PECL extension](https://pecl.php.net/package/event).
1717
* It supports the same backends as libevent.
1818
*
19+
* This loop is known to work with PHP 5.4 through PHP 7+.
20+
*
1921
* @link https://pecl.php.net/package/event
2022
*/
2123
class ExtEventLoop implements LoopInterface

src/LibEvLoop.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717
* This uses an [unofficial `libev` extension](https://github.com/m4rw3r/php-libev).
1818
* It supports the same backends as libevent.
1919
*
20+
* This loop does only work with PHP 5.
21+
* An update for PHP 7 is [unlikely](https://github.com/m4rw3r/php-libev/issues/8)
22+
* to happen any time soon.
23+
*
2024
* @see https://github.com/m4rw3r/php-libev
2125
* @see https://gist.github.com/1688204
2226
*/

src/LibEventLoop.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@
1515
* This uses the [`libevent` PECL extension](https://pecl.php.net/package/libevent).
1616
* `libevent` itself supports a number of system-specific backends (epoll, kqueue).
1717
*
18+
* This event loop does only work with PHP 5.
19+
* An [unofficial update](https://github.com/php/pecl-event-libevent/pull/2) for
20+
* PHP 7 does exist, but it is known to cause regular crashes due to `SEGFAULT`s.
21+
* To reiterate: Using this event loop on PHP 7 is not recommended.
22+
* Accordingly, the [`Factory`](#factory) will not try to use this event loop on
23+
* PHP 7.
24+
*
1825
* @link https://pecl.php.net/package/libevent
1926
*/
2027
class LibEventLoop implements LoopInterface

src/StreamSelectLoop.php

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,31 @@
1313
*
1414
* This uses the [`stream_select()`](http://php.net/manual/en/function.stream-select.php)
1515
* function and is the only implementation which works out of the box with PHP.
16-
* It does a simple `select` system call.
17-
* It's not the most performant of loops, but still does the job quite well.
16+
*
17+
* This event loop works out of the box on PHP 5.4 through PHP 7+ and HHVM.
18+
* This means that no installation is required and this library works on all
19+
* platforms and supported PHP versions.
20+
* Accordingly, the [`Factory`](#factory) will use this event loop by default if
21+
* you do not install any of the event loop extensions listed below.
22+
*
23+
* Under the hood, it does a simple `select` system call.
24+
* This system call is limited to the maximum file descriptor number of
25+
* `FD_SETSIZE` (platform dependent, commonly 1024) and scales with `O(m)`
26+
* (`m` being the maximum file descriptor number passed).
27+
* This means that you may run into issues when handling thousands of streams
28+
* concurrently and you may want to look into using one of the alternative
29+
* event loop implementations listed below in this case.
30+
* If your use case is among the many common use cases that involve handling only
31+
* dozens or a few hundred streams at once, then this event loop implementation
32+
* performs really well.
33+
*
34+
* If you want to use signal handling (see also [`addSignal()`](#addsignal) below),
35+
* this event loop implementation requires `ext-pcntl`.
36+
* This extension is only available for Unix-like platforms and does not support
37+
* Windows.
38+
* It is commonly installed as part of many PHP distributions.
39+
* If this extension is missing (or you're running on Windows), signal handling is
40+
* not supported and throws a `BadMethodCallException` instead.
1841
*
1942
* @link http://php.net/manual/en/function.stream-select.php
2043
*/

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy