php - curl_multi_exec stops if one url is 404, how can I change that? -
currently, curl multi exec stops if 1 url connects doesn't work, few questions:
1: why stop? doesn't make sense me.
2: how can make continue?
edit: here code:
$sql = mysql_query("select url shells") ; $mh = curl_multi_init(); $handles = array(); while($resultset = mysql_fetch_array($sql)){ //load urls , send data $ch = curl_init($resultset['url'] . $fullcurl); //only load 2 seconds (long enough send data) curl_setopt($ch, curlopt_timeout, 5); curl_multi_add_handle($mh, $ch); $handles[] = $ch; } // create status variable know when exec done. $running = null; //execute handles { // call exec. call non-blocking, meaning works in background. curl_multi_exec($mh,$running); // sleep while it's executing. other work here, if have any. sleep(2); // keep going until it's done. } while ($running > 0); // loop remove (close) regular handles. foreach($handles $ch) { // remove current array handle. curl_multi_remove_handle($mh, $ch); } // close multi handle curl_multi_close($mh); `
here go:
$urls = array ( 0 => 'http://bing.com', 1 => 'http://yahoo.com/thisfiledoesntexistsoitwill404.php', // 404 2 => 'http://google.com', ); $mh = curl_multi_init(); $handles = array(); foreach ($urls $url) { $handles[$url] = curl_init($url); curl_setopt($handles[$url], curlopt_timeout, 3); curl_setopt($handles[$url], curlopt_autoreferer, true); curl_setopt($handles[$url], curlopt_failonerror, true); curl_setopt($handles[$url], curlopt_followlocation, true); curl_setopt($handles[$url], curlopt_returntransfer, true); curl_setopt($handles[$url], curlopt_ssl_verifyhost, false); curl_setopt($handles[$url], curlopt_ssl_verifypeer, false); curl_multi_add_handle($mh, $handles[$url]); } $running = null; { curl_multi_exec($mh, $running); usleep(200000); } while ($running > 0); foreach ($handles $key => $value) { $handles[$key] = false; if (curl_errno($value) === 0) { $handles[$key] = curl_multi_getcontent($value); } curl_multi_remove_handle($mh, $value); curl_close($value); } curl_multi_close($mh); echo '<pre>'; print_r(array_map('htmlentities', $handles)); echo '</pre>';
returns:
array ( [http://bing.com] => <!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd"><html... [http://yahoo.com/thisfiledoesntexistsoitwill404.php] => [http://google.com] => <!doctype html><html><head><meta http-equiv="content-type" content="text/html; charset=iso-8859-1"><title>google</title>... )
as can see urls fetched, google.com comes after 404 yahoo page.
Comments
Post a Comment