too long

I'm using multi curl with simplehtmldom

i was reading this manual on simplehtmldom: http://simplehtmldom.sourceforge.net/manual_faq.htm#hosting and the example is using curl to grab 1 website, i'm trying to grab multiple which i'm using multi curl.

But when I tried using my multi curl with simplehtmldom, I'm getting an error from the header part of the page and it shows me where there's an error which is at line 39 of simple_html_dom.php

    $dom->load(call_user_func_array('file_get_contents', $args), true);

from here

// get html dom form file
function file_get_html() {
    $dom = new simple_html_dom;
    $args = func_get_args();
    $dom->load(call_user_func_array('file_get_contents', $args), true);
    return $dom;
}

This is my multi curl script.

$urls = array(
   "http://www.html2.com", //$res[0]
   "http://www.html1.com" //$res[1]
   );

$mh = curl_multi_init();

foreach ($urls as $i => $url) {
       $conn[$i]=curl_init($url);
       curl_setopt($conn[$i],CURLOPT_RETURNTRANSFER,1);//return data as string 
       curl_setopt($conn[$i],CURLOPT_FOLLOWLOCATION,1);//follow redirects
       curl_setopt($conn[$i],CURLOPT_MAXREDIRS,2);//maximum redirects
       curl_setopt($conn[$i],CURLOPT_CONNECTTIMEOUT,10);//timeout
       curl_multi_add_handle ($mh,$conn[$i]);
}

do { $n=curl_multi_exec($mh,$active); } while ($active);

foreach ($urls as $i => $url) {
       $res[$i]=curl_multi_getcontent($conn[$i]);
       curl_multi_remove_handle($mh,$conn[$i]);
       curl_close($conn[$i]);

}
curl_multi_close($mh);

and I used this

$html = file_get_html($res[0]);

Help me please!

thank you

The error you are getting is likely:

Warning: file_get_contents(): Filename cannot be empty in /tmp/simple_html_dom.php on line 39

That tells you that what you are passing into file_get_html() ($res[0]) is empty for some reason - mostly likely due to needing some additional/different CURL parameters. Indeed, if you echo out the $res[$i] in your loop, you'll see that.

Once you fix that, you'll have another problem - you are trying to pass the html content you just scraped into file_get_html() which is expecting some sort of file path, not content. In fact, file_get_contents can pull from a standard url, so you could skip all of the curl stuff completely if file_get_contents is able to pull your data correctly.

If you want to keep the curl calls, then you should be passing $res[0] into str_get_html(), not file_get_html().