Conditions | 5 |
Paths | 8 |
Total Lines | 34 |
Code Lines | 21 |
Lines | 0 |
Ratio | 0 % |
Tests | 20 |
CRAP Score | 5 |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
11 | 4 | public function multiCurl($url, $questionArray) |
|
12 | { |
||
13 | $opt = [ |
||
14 | 4 | CURLOPT_RETURNTRANSFER => true, |
|
15 | ]; |
||
16 | |||
17 | 4 | $mh = curl_multi_init(); |
|
18 | 4 | $chAll = []; |
|
19 | |||
20 | 4 | foreach ($questionArray as $q) { |
|
21 | 4 | $ch = curl_init("$url/$q"); |
|
22 | 4 | curl_setopt_array($ch, $opt); |
|
|
|||
23 | 4 | curl_multi_add_handle($mh, $ch); |
|
24 | 4 | $chAll[] = $ch; |
|
25 | } |
||
26 | |||
27 | 4 | $running = null; |
|
28 | |||
29 | do { |
||
30 | 4 | curl_multi_exec($mh, $running); |
|
31 | 4 | } while ($running); |
|
32 | |||
33 | 4 | foreach ($chAll as $ch) { |
|
34 | 4 | curl_multi_remove_handle($mh, $ch); |
|
35 | } |
||
36 | 4 | curl_multi_close($mh); |
|
37 | |||
38 | 4 | $response = []; |
|
39 | 4 | foreach ($chAll as $ch) { |
|
40 | 4 | $data = curl_multi_getcontent($ch); |
|
41 | 4 | $response[] = json_decode($data, true); |
|
42 | } |
||
43 | |||
44 | 4 | return $response; |
|
45 | } |
||
47 |