@@ -10,7 +10,7 @@ built on top of [ReactPHP](https://reactphp.org/).
10
10
Let's say you crawl a page and find that you need to send 100 HTTP requests to
11
11
following pages which each takes ` 0.2s ` . You can either send them all
12
12
sequentially (taking around ` 20s ` ) or you can use
13
- [ ReactPHP] ( https://reactphp.org ) to concurrently request all your pages at the
13
+ [ ReactPHP] ( https://reactphp.org/ ) to concurrently request all your pages at the
14
14
same time. This works perfectly fine for a small number of operations, but
15
15
sending an excessive number of requests can either take up all resources on your
16
16
side or may get you banned by the remote side as it sees an unreasonable number
@@ -84,12 +84,14 @@ $q = new Clue\React\Mq\Queue(3, null, function ($url) use ($browser) {
84
84
foreach ($urls as $url) {
85
85
$q($url)->then(function (Psr\Http\Message\ResponseInterface $response) use ($url) {
86
86
echo $url . ': ' . $response->getBody()->getSize() . ' bytes' . PHP_EOL;
87
- });
87
+ }, function (Exception $e) {
88
+ echo 'Error: ' . $e->getMessage() . PHP_EOL;
89
+ } );
88
90
}
89
91
90
92
```
91
93
92
- See also the [ examples] ( examples ) .
94
+ See also the [ examples] ( examples/ ) .
93
95
94
96
## Usage
95
97
@@ -196,6 +198,10 @@ interface that makes it easy to react to when an operation is completed (i.e.
196
198
either successfully fulfilled or rejected with an error):
197
199
198
200
``` php
201
+ <?php
202
+
203
+ require __DIR__ . '/vendor/autoload.php';
204
+
199
205
$promise->then(
200
206
function ($result) {
201
207
var_dump('Result received', $result);
@@ -284,6 +290,10 @@ schedule all jobs while limiting concurrency to ensure no more than
284
290
resolves with the results of all jobs on success.
285
291
286
292
``` php
293
+ <?php
294
+
295
+ require __DIR__ . '/vendor/autoload.php';
296
+
287
297
$browser = new React\Http\Browser();
288
298
289
299
$promise = Queue::all(3, $urls, function ($url) use ($browser) {
@@ -292,6 +302,8 @@ $promise = Queue::all(3, $urls, function ($url) use ($browser) {
292
302
293
303
$promise->then(function (array $responses) {
294
304
echo 'All ' . count($responses) . ' successful!' . PHP_EOL;
305
+ }, function (Exception $e) {
306
+ echo 'Error: ' . $e->getMessage() . PHP_EOL;
295
307
});
296
308
```
297
309
@@ -360,6 +372,10 @@ resolves with the result of the first job on success and will then try
360
372
to ` cancel() ` all outstanding jobs.
361
373
362
374
``` php
375
+ <?php
376
+
377
+ require __DIR__ . '/vendor/autoload.php';
378
+
363
379
$browser = new React\Http\Browser();
364
380
365
381
$promise = Queue::any(3, $urls, function ($url) use ($browser) {
@@ -368,6 +384,8 @@ $promise = Queue::any(3, $urls, function ($url) use ($browser) {
368
384
369
385
$promise->then(function (ResponseInterface $response) {
370
386
echo 'First response: ' . $response->getBody() . PHP_EOL;
387
+ }, function (Exception $e) {
388
+ echo 'Error: ' . $e->getMessage() . PHP_EOL;
371
389
});
372
390
```
373
391
@@ -449,6 +467,10 @@ Similarly, you can also wrap this in a function to provide a simple API and hide
449
467
all the async details from the outside:
450
468
451
469
``` php
470
+ <?php
471
+
472
+ require __DIR__ . '/vendor/autoload.php';
473
+
452
474
use function React\Async\await;
453
475
454
476
/**
0 commit comments