suche nach in der

curl_multi_getcontent> <curl_multi_close
Last updated: Fri, 18 May 2012

view this page in

curl_multi_exec

(PHP 5)

curl_multi_execFührt die Unter-Verbindungen des cURL-Handles aus

Beschreibung

int curl_multi_exec ( resource $mh , int &$still_running )

Verarbeitet alle Handles; diese Methode kann unabhängig davon aufgerufen werden, ob eines der Handles Daten lesen oder schreiben muß.

Parameter-Liste

mh

Ein von curl_multi_init() zurückgegebenes cURL-Multihandle.

still_running

Eine Referenz auf ein Flag um festzustellen, ob auf einem oder mehreren Handles noch gearbeitet wird.

Rückgabewerte

Ein cURL-Code der in den cURL Vordefinierten Konstanten definiert ist.

Hinweis:

Es werden nur Fehler zurückgegeben, die den Handle-Stack betreffen. Auch wenn CURLM_OK zurückgegeben wird können auf einzelnen Handles Fehler aufgetreten sein.

Beispiele

Beispiel #1 curl_multi_exec()-Beispiel

In diesem Beispiel werden zwei cURL-Handles erstellt, einem Mehrfach-Handle hinzugefügt und anschließend parallel ausgeführt.

<?php
// zwei cURL Resourcen erstellen
$ch1 curl_init();
$ch2 curl_init();

// URL und weitere Optionen setzen
curl_setopt($ch1CURLOPT_URL"http://lxr.php.net/");
curl_setopt($ch1CURLOPT_HEADER0);
curl_setopt($ch2CURLOPT_URL"http://www.php.net/");
curl_setopt($ch2CURLOPT_HEADER0);

// Mehrfach-Handle erstellen
$mh curl_multi_init();

// die zuvor erstellten Handles hinzufügen
curl_multi_add_handle($mh,$ch1);
curl_multi_add_handle($mh,$ch2);

$active null;
// Handles ausführen
do {
    
$mrc curl_multi_exec($mh$active);
} while (
$mrc == CURLM_CALL_MULTI_PERFORM);

while (
$active && $mrc == CURLM_OK) {
    if (
curl_multi_select($mh) != -1) {
        do {
            
$mrc curl_multi_exec($mh$active);
        } while (
$mrc == CURLM_CALL_MULTI_PERFORM);
    }
}

//close the handles
curl_multi_remove_handle($mh$ch1);
curl_multi_remove_handle($mh$ch2);
curl_multi_close($mh);

?>

Siehe auch



add a note add a note User Contributed Notes
curl_multi_exec
substr(&#34;iscampifriese&#34;,1,11) dot &#34; at beer dot com&#34;
04-Jul-2007 03: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 07: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);
?>

curl_multi_getcontent> <curl_multi_close
Last updated: Fri, 18 May 2012