fridalindgren91 /
ramverk1-module
| 1 | <?php |
||||
| 2 | namespace Anax\DI; |
||||
| 3 | |||||
| 4 | use Anax\Commons\ContainerInjectableInterface; |
||||
| 5 | use Anax\Commons\ContainerInjectableTrait; |
||||
| 6 | |||||
| 7 | class Curl implements ContainerInjectableInterface |
||||
| 8 | { |
||||
| 9 | use ContainerInjectableTrait; |
||||
| 10 | |||||
| 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); |
|||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||||
| 23 | 4 | curl_multi_add_handle($mh, $ch); |
|||
|
0 ignored issues
–
show
It seems like
$ch can also be of type false; however, parameter $ch of curl_multi_add_handle() does only seem to accept resource, maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 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 | } |
||||
| 46 | } |
||||
| 47 |