curl_multi_exec

(PHP 5)

curl_multi_exec -- Run the sub-connections of the current cURL handle

说明

int curl_multi_exec ( resource mh, int &still_running )

警告

本函数暂无文档,仅有参数列表。

参数

mh

A cURL multi handle returned by curl_multi_init().

still_running


add a note add a note User Contributed Notes
substr("iscampifriese",1,11) dot " at beer dot com"
04-Jul-2007 01:10
If you are using mulit handles and you wish to re-execute any of them (if they timed out or something), then you need to remove the handles from the mulit-handle and then re-add them in order to get them to re-execute.  Otherwise cURL will just give you back the same results again without actually retrying.
dtorop933 at gmail dot com
07-Jan-2005 06:21
<?php
$connomains
= array(
  
"http://www.cnn.com/",
  
"http://www.canada.com/",
  
"http://www.yahoo.com/"
);

$mh = curl_multi_init();

foreach (
$connomains as $i => $url) {
 
$conn[$i] = curl_init($url);
 
curl_setopt($conn[$i], CURLOPT_RETURNTRANSFER, 1);
 
curl_multi_add_handle ($mh,$conn[$i]);
}

// start performing the request
do {
 
$mrc = curl_multi_exec($mh, $active);
} while (
$mrc == CURLM_CALL_MULTI_PERFORM);

while (
$active and $mrc == CURLM_OK) {
 
// wait for network
 
if (curl_multi_select($mh) != -1) {
  
// pull in any new data, or at least handle timeouts
  
do {
    
$mrc = curl_multi_exec($mh, $active);
   } while (
$mrc == CURLM_CALL_MULTI_PERFORM);
  }
}

if (
$mrc != CURLM_OK) {
  print
"Curl multi read error $mrc\n";
}

// retrieve data
foreach ($connomains as $i => $url) {
  if ((
$err = curl_error($conn[$i])) == '') {
  
$res[$i]=curl_multi_getcontent($conn[$i]);
  } else {
   print
"Curl error on handle $i: $err\n";
  }
 
curl_multi_remove_handle($mh,$conn[$i]);
 
curl_close($conn[$i]);
}
curl_multi_close($mh);

print_r($res);
?>