-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconnection_pooling.php
46 lines (38 loc) · 1.25 KB
/
connection_pooling.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?php declare(strict_types=1);
use EdgeTelemetrics\React\Http\Browser;
use function React\Async\await;
include __DIR__ . '/../vendor/autoload.php';
$browser = new Browser([
CURLOPT_TIMEOUT => 20,
]);
React\Async\parallel([
function () use ($browser) {
return $browser->get("https://www.google.com");
},
function () use ($browser) {
return $browser->get("https://www.google.com");
},
]
)->then(function (array $results) {
foreach ($results as $index => $response) {
echo "parallel $index: " . json_encode($response->getHeader('X-Connection'), JSON_PRETTY_PRINT) . "\n";
}
}, function (Exception $e) {
echo 'Error: ' . $e->getMessage() . PHP_EOL;
});
React\Async\series([
function () use ($browser) {
return $browser->get("https://www.google.com");
},
function () use ($browser) {
return $browser->get("https://www.google.com");
},
]
)->then(function (array $results) {
foreach ($results as $index => $response) {
echo "series $index: " . json_encode($response->getHeader('X-Connection'), JSON_PRETTY_PRINT) . "\n";
}
}, function (Exception $e) {
echo 'Error: ' . $e->getMessage() . PHP_EOL;
});
//await($browser->request('/'));