| Conditions | 5 |
| Paths | 8 |
| Total Lines | 27 |
| Code Lines | 19 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 19 |
| CRAP Score | 5 |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 21 | 2 | public function fetchMultiple($urls) |
|
| 22 | { |
||
| 23 | 2 | $mh = curl_multi_init(); |
|
| 24 | 2 | $chAll = []; |
|
| 25 | 2 | foreach ($urls as $url) { |
|
| 26 | 2 | $ch = curl_init($url); |
|
| 27 | 2 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
|
| 28 | 2 | curl_multi_add_handle($mh, $ch); |
|
| 29 | 2 | $chAll[] = $ch; |
|
| 30 | } |
||
| 31 | |||
| 32 | 2 | $running = null; |
|
| 33 | do { |
||
| 34 | 2 | curl_multi_exec($mh, $running); |
|
| 35 | 2 | } while ($running); |
|
| 36 | |||
| 37 | 2 | foreach ($chAll as $ch) { |
|
| 38 | 2 | curl_multi_remove_handle($mh, $ch); |
|
| 39 | } |
||
| 40 | 2 | curl_multi_close($mh); |
|
| 41 | |||
| 42 | 2 | $response = []; |
|
| 43 | 2 | foreach ($chAll as $ch) { |
|
| 44 | 2 | $data = curl_multi_getcontent($ch); |
|
| 45 | 2 | $response[] = json_decode($data, true); |
|
| 46 | } |
||
| 47 | 2 | return $response; |
|
| 48 | } |
||
| 50 |