@@ -43,32 +43,44 @@ return value.
43
43
44
44
## Requirements
45
45
46
- At the moment, fibers are available as a development version by installing
47
- [ react/async] ( https://github.com/reactphp/async ) from a development branch
48
- like this:
46
+ X provides support for fibers out of the box, so there's nothing special you
47
+ have to install. You wouldn't usually have to directly interface with fibers,
48
+ but the underlying APIs are provided thanks to the common
49
+ [ reactphp/async] ( https://github.com/reactphp/async ) package.
49
50
50
- ``` bash
51
- $ composer require react/async:^4@dev
52
- ```
53
-
54
- Installing this package version requires PHP 8.1+ (2021-11-25) as fibers are a
55
- core ingredient of PHP 8.1+. We understand that adoption of this very new PHP
56
- version is going to take some time, so we also provide a limited
57
- [ compatibility mode] ( #compatibility-mode ) that also works on PHP 7.1+ to ease
58
- upgrading.
51
+ Fibers are a core ingredient of PHP 8.1+ (released 2021-11-25), but the same
52
+ syntax also works on older PHP versions to some degree if you only have limited
53
+ concurrency. For production usage, we highly recommend using PHP 8.1+.
59
54
60
- > ℹ️ ** Coroutines and Promises work anywhere**
55
+ > ⚠️ ** Compatibility mode**
56
+ >
57
+ > For production usage, we highly recommend using PHP 8.1+. If you're using the
58
+ > ` await() ` function in compatibility mode with older PHP versions, it may stop
59
+ > the loop from running and may print a warning like this:
60
+ >
61
+ > ```
62
+ > Warning: Loop restarted. Upgrade to react/async v4 recommended […]
63
+ > ```
64
+ >
65
+ > Internally, the compatibility mode will cause recursive loop executions when
66
+ > dealing with concurrent requests. This should work fine for development
67
+ > purposes and fast controllers with low concurrency, but may cause issues in
68
+ > production with high concurrency.
61
69
>
62
- > Remember, we also provide support for [ coroutines] ( coroutines.md ) and
63
- > [ promises] ( promises.md ) on all supported PHP versions as an alternative.
64
- > Coroutines allow consuming async APIs in a way that resembles a synchronous
65
- > code flow using the ` yield ` keyword. You can also directly use promises as a
66
- > core building block used in all our async APIs for maximum performance.
70
+ > We understand that adoption of this very new PHP version is going to take some
71
+ > time and we acknowledge that this is probably one of the largest limitations
72
+ > of using fibers at the moment for many. We're committed to providing long-term
73
+ > support (LTS) options and providing a smooth upgrade path. As such, we also
74
+ > provide limited support for older PHP versions using a compatible API without
75
+ > taking advantage of newer language features. This way, you have a much
76
+ > smoother upgrade path, as you can already start using the future API for
77
+ > testing and development purposes and upgrade your PHP version for production
78
+ > use at a later time.
67
79
68
80
## Usage
69
81
70
- Once installed (see requirements above), fibers are very easy to use – because
71
- you simply can't see them – which in turn makes them quite hard to explain.
82
+ Fibers are very easy to use – because you simply can't see them – which in turn
83
+ makes them a bit harder to explain.
72
84
73
85
The gist is that whenever you're working with an async API that returns a
74
86
promise, you simply call the `await()` function on it in order to "await" its
@@ -124,56 +136,6 @@ Coroutines allow consuming async APIs in a way that resembles a synchronous
124
136
code flow using the ` yield ` keyword. You can also directly use promises as a
125
137
core building block used in all our async APIs for maximum performance.
126
138
127
- ### Compatibility mode
128
-
129
- Fibers are a core ingredient of PHP 8.1+, but the same syntax also works on
130
- older PHP versions to some degree if you only have limited concurrency.
131
-
132
- For production usage, we highly recommend using PHP 8.1+. At the moment, fibers
133
- are available as a development version by installing
134
- [ react/async] ( https://github.com/reactphp/async ) from a development branch
135
- like this:
136
-
137
- ``` bash
138
- $ composer require react/async:^4@dev
139
- ```
140
-
141
- Installing this package version requires PHP 8.1+ (2021-11-25) as fibers are a
142
- core ingredient of PHP 8.1+. We understand that adoption of this very new PHP
143
- version is going to take some time, so we acknowledge that this is probably one
144
- of the largest limitations of using fibers at the moment.
145
-
146
- But don't worry, we're committed to providing long-term support (LTS) options
147
- and providing a smooth upgrade path. As such, we also provide limited support
148
- for older PHP versions using a compatible API without taking advantage of newer
149
- language features. By installing the v3 development version of this package, the
150
- same ` await() ` syntax also works on PHP 7.1+ to some degree if you only have
151
- limited concurrency. You can install either supported development version like
152
- this:
153
-
154
- ``` bash
155
- $ composer require react/async:" ^4@dev || ^3@dev"
156
- ```
157
-
158
- This way, you have a much smoother upgrade path, as you can already start using
159
- the future API for testing and development purposes and upgrade your PHP version
160
- for production use at a later time.
161
-
162
- > ⚠️ ** Production usage**
163
- >
164
- > For production usage, we highly recommend using PHP 8.1+. If you're using the
165
- > ` await() ` function in compatibility mode, it may stop the loop from running and
166
- > may print a warning like this:
167
- >
168
- > ```
169
- > Warning: Loop restarted. Upgrade to react/async v4 recommended […]
170
- > ```
171
- >
172
- > Internally, the compatibility mode will cause recursive loop executions when
173
- > dealing with concurrent requests. This should work fine for development
174
- > purposes and fast controllers with low concurrency, but may cause issues in
175
- > production with high concurrency.
176
-
177
139
### How do fibers work?
178
140
179
141
Fibers are a means of creating code blocks that can be paused and resumed, but
0 commit comments