-2

the error log file that appears with this error:

Error on Oct 17, 2016 1:44AM - Invalid argument supplied for foreach() in /home/xxxxx/public_html/root/controllers/post/admin.php on line 391

private function curlMultiRequest($urls, $options = array()) {
        $ch = array();
        $results = array();
        $mh = curl_multi_init();
        foreach($urls as $key => $val) {        < -------------391 row
            $ch[$key] = curl_init();
            if ($options) {
                curl_setopt_array($ch[$key], $options);
            }
            curl_setopt($ch[$key], CURLOPT_URL, $val);
            curl_setopt($ch[$key], CURLOPT_HEADER, 0);
            curl_setopt($ch[$key], CURLOPT_RETURNTRANSFER, TRUE);
            curl_multi_add_handle($mh, $ch[$key]);
        }
Anagashi
  • 1
  • 1
  • 1
  • At least show us how you call this function as that is where the mistake is. You are obviously not passing an array as the `$urls` parameter on the function call – RiggsFolly Oct 17 '16 at 00:50

3 Answers3

0

$urls must be array so you could do this:

...
if(is_array($urls)){
    foreach($urls as $key => $val){
        ...
    }
}else{
    // handle unexpected state
}
...

or

private function curlMultiRequest(array $urls, $options = array()) { ... }
Kazz
  • 1,030
  • 8
  • 16
0

Because $url being passed isn't an array or is empty? Try doing this to see what is being passed to the function:

print_r($url);exit; 
jbschwartz
  • 28
  • 2
-1

you have to check if the argument is an array or not and you can take alook at this situation Invalid argument supplied for foreach()

Community
  • 1
  • 1
Ali Sadran
  • 264
  • 2
  • 4