@@ -18,19 +18,25 @@ For the code of the current stable 0.4.x release, checkout the
18
18
19
19
* [ Quickstart example] ( #quickstart-example )
20
20
* [ Usage] ( #usage )
21
- * [ Factory] ( #factory )
22
- * [ Loop implementations] ( #loop-implementations )
23
- * [ addtimer()] ( #addtimer )
24
- * [ addPeriodicTimer()] ( #addperiodictimer )
25
- * [ cancelTimer()] ( #canceltimer )
26
- * [ isTimerActive()] ( #istimeractive )
27
- * [ futureTick()] ( #futuretick )
28
- * [ addSignal()] ( #addsignal )
29
- * [ removeSignal()] ( #removesignal )
30
- * [ addReadStream()] ( #addreadstream )
31
- * [ addWriteStream()] ( #addwritestream )
32
- * [ removeReadStream()] ( #removereadstream )
33
- * [ removeWriteStream()] ( #removewritestream )
21
+ * [ Factory] ( #factory )
22
+ * [ create()] ( #create )
23
+ * [ Loop implementations] ( #loop-implementations )
24
+ * [ StreamSelectLoop] ( #streamselectloop )
25
+ * [ LibEventLoop] ( #libeventloop )
26
+ * [ LibEvLoop] ( #libevloop )
27
+ * [ ExtEventLoop] ( #exteventloop )
28
+ * [ LoopInterface] ( #loopinterface )
29
+ * [ addtimer()] ( #addtimer )
30
+ * [ addPeriodicTimer()] ( #addperiodictimer )
31
+ * [ cancelTimer()] ( #canceltimer )
32
+ * [ isTimerActive()] ( #istimeractive )
33
+ * [ futureTick()] ( #futuretick )
34
+ * [ addSignal()] ( #addsignal )
35
+ * [ removeSignal()] ( #removesignal )
36
+ * [ addReadStream()] ( #addreadstream )
37
+ * [ addWriteStream()] ( #addwritestream )
38
+ * [ removeReadStream()] ( #removereadstream )
39
+ * [ removeWriteStream()] ( #removewritestream )
34
40
* [ Install] ( #install )
35
41
* [ Tests] ( #tests )
36
42
* [ License] ( #license )
@@ -106,49 +112,79 @@ $loop->run();
106
112
purposes.
107
113
3 . The loop is run with a single ` $loop->run() ` call at the end of the program.
108
114
109
- ## Factory
115
+ ### Factory
110
116
111
117
The ` Factory ` class exists as a convenient way to pick the best available
112
- [ loop implementation] ( #loop-implementations ) .
118
+ [ event loop implementation] ( #loop-implementations ) .
113
119
114
- The ` create(): LoopInterface ` method can be used to create a new loop
120
+ #### create()
121
+
122
+ The ` create(): LoopInterface ` method can be used to create a new event loop
115
123
instance:
116
124
117
125
``` php
118
126
$loop = React\EventLoop\Factory::create();
119
127
```
120
128
121
- This method always returns an instance implementing ` LoopInterface ` ,
122
- the actual loop implementation is an implementation detail.
129
+ This method always returns an instance implementing [ ` LoopInterface ` ] ( #loopinterface ) ,
130
+ the actual [ event loop implementation] ( #loop-implementations ) is an implementation detail.
123
131
124
132
This method should usually only be called once at the beginning of the program.
125
133
126
- ## Loop implementations
127
-
128
- In addition to the interface there are the following implementations provided:
129
-
130
- * ` StreamSelectLoop ` : This is the only implementation which works out of the
131
- box with PHP. It does a simple ` select ` system call. It's not the most
132
- performant of loops, but still does the job quite well.
134
+ ### Loop implementations
133
135
134
- * ` LibEventLoop ` : This uses the ` libevent ` pecl extension. ` libevent ` itself
135
- supports a number of system-specific backends (epoll, kqueue) .
136
+ In addition to the [ ` LoopInterface ` ] ( #loopinterface ) , there are a number of
137
+ event loop implementations provided .
136
138
137
- * ` LibEvLoop ` : This uses the ` libev ` pecl extension
138
- ([ github] ( https://github.com/m4rw3r/php-libev ) ). It supports the same
139
- backends as libevent.
140
-
141
- * ` ExtEventLoop ` : This uses the ` event ` pecl extension. It supports the same
142
- backends as libevent.
143
-
144
- All of the loops support these features:
139
+ All of the event loops support these features:
145
140
146
141
* File descriptor polling
147
142
* One-off timers
148
143
* Periodic timers
149
144
* Deferred execution on future loop tick
150
145
151
- ### addTimer()
146
+ For most consumers of this package, the underlying event loop implementation is
147
+ an implementation detail.
148
+ You should use the [ ` Factory ` ] ( #factory ) to automatically create a new instance.
149
+
150
+ Advanced! If you explicitly need a certain event loop implementation, you can
151
+ manually instantiate one of the following classes.
152
+ Note that you may have to install the required PHP extensions for the respective
153
+ event loop implementation first or this may result in a fatal error.
154
+
155
+ #### StreamSelectLoop
156
+
157
+ A ` stream_select() ` based event loop.
158
+
159
+ This uses the [ ` stream_select() ` ] ( http://php.net/manual/en/function.stream-select.php )
160
+ 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.
163
+
164
+ #### LibEventLoop
165
+
166
+ An ` ext-libevent ` based event loop.
167
+
168
+ This uses the [ ` libevent ` PECL extension] ( https://pecl.php.net/package/libevent ) .
169
+ ` libevent ` itself supports a number of system-specific backends (epoll, kqueue).
170
+
171
+ #### LibEvLoop
172
+
173
+ An ` ext-libev ` based event loop.
174
+
175
+ This uses an [ unofficial ` libev ` extension] ( https://github.com/m4rw3r/php-libev ) .
176
+ It supports the same backends as libevent.
177
+
178
+ #### ExtEventLoop
179
+
180
+ An ` ext-event ` based event loop.
181
+
182
+ This uses the [ ` event ` PECL extension] ( https://pecl.php.net/package/event ) .
183
+ It supports the same backends as libevent.
184
+
185
+ ### LoopInterface
186
+
187
+ #### addTimer()
152
188
153
189
The ` addTimer(float $interval, callable $callback): TimerInterface ` method can be used to
154
190
enqueue a callback to be invoked once after the given interval.
@@ -195,7 +231,7 @@ hello('Tester', $loop);
195
231
The execution order of timers scheduled to execute at the same time is
196
232
not guaranteed.
197
233
198
- ### addPeriodicTimer()
234
+ #### addPeriodicTimer()
199
235
200
236
The ` addPeriodicTimer(float $interval, callable $callback): TimerInterface ` method can be used to
201
237
enqueue a callback to be invoked repeatedly after the given interval.
@@ -249,7 +285,7 @@ hello('Tester', $loop);
249
285
The execution order of timers scheduled to execute at the same time is
250
286
not guaranteed.
251
287
252
- ### cancelTimer()
288
+ #### cancelTimer()
253
289
254
290
The ` cancelTimer(TimerInterface $timer): void ` method can be used to
255
291
cancel a pending timer.
@@ -264,7 +300,7 @@ Calling this method on a timer instance that has not been added to this
264
300
loop instance or on a timer that is not "active" (or has already been
265
301
cancelled) has no effect.
266
302
267
- ### isTimerActive()
303
+ #### isTimerActive()
268
304
269
305
The ` isTimerActive(TimerInterface $timer): bool ` method can be used to
270
306
check if a given timer is active.
@@ -274,7 +310,7 @@ via [`addTimer()`](#addtimer) or [`addPeriodicTimer()`](#addperiodictimer)
274
310
and has not been cancelled via [ ` cancelTimer() ` ] ( #canceltimer ) and is not
275
311
a non-periodic timer that has already been triggered after its interval.
276
312
277
- ### futureTick()
313
+ #### futureTick()
278
314
279
315
The ` futureTick(callable $listener): void ` method can be used to
280
316
schedule a callback to be invoked on a future tick of the event loop.
@@ -322,7 +358,7 @@ echo 'a';
322
358
323
359
See also [ example #3 ] ( examples ) .
324
360
325
- ### addSignal()
361
+ #### addSignal()
326
362
327
363
The ` addSignal(int $signal, callable $listener): void ` method can be used to
328
364
register a listener to be notified when a signal has been caught by this process.
@@ -356,7 +392,7 @@ missing.
356
392
** Note: A listener can only be added once to the same signal, any
357
393
attempts to add it more then once will be ignored.**
358
394
359
- ### removeSignal()
395
+ #### removeSignal()
360
396
361
397
The ` removeSignal(int $signal, callable $listener): void ` method can be used to
362
398
remove a previously added signal listener.
@@ -367,7 +403,7 @@ $loop->removeSignal(SIGINT, $listener);
367
403
368
404
Any attempts to remove listeners that aren't registered will be ignored.
369
405
370
- ### addReadStream()
406
+ #### addReadStream()
371
407
372
408
> Advanced! Note that this low-level API is considered advanced usage.
373
409
Most use cases should probably use the higher-level
@@ -410,7 +446,7 @@ read event listener for this stream.
410
446
The execution order of listeners when multiple streams become ready at
411
447
the same time is not guaranteed.
412
448
413
- ### addWriteStream()
449
+ #### addWriteStream()
414
450
415
451
> Advanced! Note that this low-level API is considered advanced usage.
416
452
Most use cases should probably use the higher-level
@@ -453,15 +489,15 @@ write event listener for this stream.
453
489
The execution order of listeners when multiple streams become ready at
454
490
the same time is not guaranteed.
455
491
456
- ### removeReadStream()
492
+ #### removeReadStream()
457
493
458
494
The ` removeReadStream(resource $stream): void ` method can be used to
459
495
remove the read event listener for the given stream.
460
496
461
497
Removing a stream from the loop that has already been removed or trying
462
498
to remove a stream that was never added or is invalid has no effect.
463
499
464
- ### removeWriteStream()
500
+ #### removeWriteStream()
465
501
466
502
The ` removeWriteStream(resource $stream): void ` method can be used to
467
503
remove the write event listener for the given stream.
@@ -480,6 +516,14 @@ This will install the latest supported version:
480
516
$ composer require react/event-loop
481
517
```
482
518
519
+ This project aims to run on any platform and thus does not require any PHP
520
+ extensions and supports running on legacy PHP 5.4 through current PHP 7+ and
521
+ HHVM.
522
+ It's * highly recommended to use PHP 7+* for this project.
523
+
524
+ Installing any of the event loop extensions is suggested, but entirely optional.
525
+ See also [ event loop implementations] ( #loop-implementations ) for more details.
526
+
483
527
## Tests
484
528
485
529
To run the test suite, you first need to clone this repo and then install all
0 commit comments