| Conditions | 4 |
| Paths | 4 |
| Total Lines | 42 |
| Code Lines | 22 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 22 |
| CRAP Score | 4 |
| Changes | 0 | ||
| 1 | <?php |
||
| 17 | 1 | public function get(array $urls, $header) : array |
|
| 18 | { |
||
| 19 | 1 | $id = 1; |
|
| 20 | 1 | $data = []; |
|
| 21 | 1 | $headers = $header; |
|
| 22 | |||
| 23 | //create the multiple cURL handle |
||
| 24 | 1 | $curlHandler = curl_multi_init(); |
|
| 25 | |||
| 26 | 1 | foreach ($urls as $url) { |
|
| 27 | // create cURL resources |
||
| 28 | 1 | ${"ch$id"} = curl_init($url); |
|
| 29 | |||
| 30 | // set URL and other appropriate options |
||
| 31 | 1 | curl_setopt(${"ch$id"}, CURLOPT_RETURNTRANSFER, true); |
|
| 32 | 1 | curl_setopt(${"ch$id"}, CURLOPT_HTTPHEADER, $headers); |
|
| 33 | |||
| 34 | //add the handle |
||
| 35 | 1 | curl_multi_add_handle($curlHandler, ${"ch$id"}); |
|
| 36 | |||
| 37 | 1 | $id++; |
|
| 38 | } |
||
| 39 | |||
| 40 | //execute the multi handle |
||
| 41 | 1 | $running = null; |
|
| 42 | do { |
||
| 43 | 1 | curl_multi_exec($curlHandler, $running); |
|
| 44 | 1 | } while ($running); |
|
| 45 | |||
| 46 | 1 | $id = 1; |
|
| 47 | |||
| 48 | 1 | foreach ($urls as $url) { |
|
| 49 | //close the handle |
||
| 50 | 1 | curl_multi_remove_handle($curlHandler, ${"ch$id"}); |
|
| 51 | 1 | $contents = json_decode(curl_multi_getcontent(${"ch$id"}), JSON_UNESCAPED_UNICODE |true); |
|
|
|
|||
| 52 | 1 | $data[] = $contents; |
|
| 53 | 1 | $id++; |
|
| 54 | } |
||
| 55 | |||
| 56 | 1 | curl_multi_close($curlHandler); |
|
| 57 | |||
| 58 | 1 | return $data; |
|
| 59 | } |
||
| 61 |