Conditions | 7 |
Paths | 16 |
Total Lines | 40 |
Code Lines | 22 |
Lines | 0 |
Ratio | 0 % |
Tests | 22 |
CRAP Score | 7 |
Changes | 1 | ||
Bugs | 0 | Features | 1 |
1 | <?php |
||
24 | 9 | public function multiCurl($urls) |
|
25 | { |
||
26 | 9 | $cHandles = []; |
|
27 | |||
28 | //create the multiple cURL handle |
||
29 | 9 | $mh = curl_multi_init(); |
|
30 | |||
31 | 9 | $count = count($urls); |
|
32 | |||
33 | // set URL and other appropriate options |
||
34 | 9 | for ($i = 0; $i < $count; $i++) { |
|
35 | 9 | $cHandles[$i] = curl_init(); |
|
36 | 9 | curl_setopt($cHandles[$i], CURLOPT_RETURNTRANSFER, true); |
|
37 | 9 | curl_setopt($cHandles[$i], CURLOPT_URL, $urls[$i]); |
|
38 | 9 | curl_setopt($cHandles[$i], CURLOPT_HEADER, 0); |
|
39 | |||
40 | 9 | curl_multi_add_handle($mh, $cHandles[$i]); |
|
41 | } |
||
42 | |||
43 | //execute the multi handle |
||
44 | do { |
||
45 | 9 | $status = curl_multi_exec($mh, $active); |
|
46 | 9 | if ($active) { |
|
47 | 9 | curl_multi_select($mh); |
|
48 | } |
||
49 | 9 | } while ($active && $status == CURLM_OK); |
|
50 | |||
51 | 9 | $json = []; |
|
52 | 9 | $countCHandles = count($cHandles); |
|
53 | 9 | for ($i=0; $i < $countCHandles; $i++) { |
|
54 | 9 | array_push($json, curl_multi_getcontent($cHandles[$i])); |
|
55 | } |
||
56 | |||
57 | 9 | for ($i = 0; $i < $count; $i++) { |
|
58 | 9 | curl_multi_remove_handle($mh, $cHandles[$i]); |
|
59 | } |
||
60 | |||
61 | 9 | curl_multi_close($mh); |
|
62 | |||
63 | 9 | return $json; |
|
64 | } |
||
66 |