-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.php
42 lines (32 loc) · 1.07 KB
/
example.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
<?php
require(__DIR__ . '/bootstrap.php');
$totalTime = microtime(true);
$multi = new \MultiCurl\MultiCurl();
$maxSleep = 5;
$keys = [];
$addCurlHandles = microtime(true);
$keys[] = $multi->addCurl(getHandle($maxSleep));
for ($i = 0; $i < 2; $i++) {
$keys[] = $multi->addCurl(getHandle(random_int(1, $maxSleep)));
}
echo 'Add curl handles: ' . (microtime(true) - $addCurlHandles) . "\n";
$sendRequests = microtime(true);
$multi->sendAllRequests();
echo 'Sending requests: ' . (microtime(true) - $sendRequests) . "\n";
/**/
$loop = microtime(true);
while (microtime(true) - $loop < 2) {
usleep(100);
}
echo 'Loop: ' . (microtime(true) - $loop) . "\n";
/**/
$getResults = microtime(true);
while ($result = $multi->getNextResult()) {
foreach ($result as $key => $response) {
echo $response['response'] . "\n";
}
}
echo 'Get results: ' . (microtime(true) - $getResults) . "\n";
$totalTime = microtime(true) - $totalTime;
echo 'Total time: ' . $totalTime . "\n";
assert($maxSleep === (int)floor($totalTime), 'Script execution should not take much longer than the longest curl request');