-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample-callback.php
More file actions
30 lines (20 loc) · 876 Bytes
/
example-callback.php
File metadata and controls
30 lines (20 loc) · 876 Bytes
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
<?php
require(__DIR__ . '/bootstrap.php');
$totalTime = microtime(true);
$multi = new \MultiCurl\Callback();
$maxSleep = 3;
$asyncCallback = function ($response) {
echo "Async request completed in {$response['info']['total_time']}\n";
echo $response['response'] . "\n";
};
$multi->requestAsync(getHandle($maxSleep - 2), $asyncCallback);
$multi->requestAsync(getHandle($maxSleep), $asyncCallback);
$multi->requestAsync(getHandle($maxSleep - 1), $asyncCallback);
$multi->requestSync(getHandle($maxSleep - 1), function($response) {
echo "Sync request completed in {$response['info']['total_time']}\n";
echo $response['response'] . "\n";
});
$multi->read();
$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');