-
Notifications
You must be signed in to change notification settings - Fork 4
/
test.php
53 lines (42 loc) · 1.37 KB
/
test.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
47
48
49
50
51
52
53
<?php
#used to test the max number of parallel requests we can make.
function queryPlugins() {
$response = new stdClass();
$pool = new HttpRequestPool();
$pluginUrls = array();
for ($i=0; $i<10; $i++) {
$pluginUrls[] = "http://localhost/plugins/metrics/Wikipedia/index.cgi?foo=" . $i;
}
foreach ($pluginUrls as $sourceName => $pluginUrl) {
$request = new HttpRequest($pluginUrl, HTTP_METH_GET);
$dataToSend = "{}";
$encoded_data = json_encode($dataToSend);
$request->setPostFields(array('query' => $encoded_data));
$pool->attach($request);
}
$pool->send();
foreach ($pool as $request) {
$body = $request->getResponseBody();
echo $body . "<br>*****************************************<br><br><br>";
}
}
function testHttpPool() {
$startTime = microtime(TRUE);
$pluginUrls = array();
for ($i=0; $i<15; $i++) {
$pluginUrls[] = "http://localhost";
}
$pool = new HttpRequestPool();
foreach ($pluginUrls as $k => $url) {
$request = new HttpRequest($url, HTTP_METH_GET);
$pool->attach($request);
}
$pool->send();
$finishedRequests = $pool->getAttachedRequests();
foreach($finishedRequests as $request) {
print_r($request->getResponseInfo());
}
echo "total time: " . (microtime(TRUE) - $startTime);
}
testHttpPool();
?>