2011-01-01 16 views

Antwort

0

Ich weiß nicht, wie Sie curl_multi implementieren, aber dieses Skript, basierend auf Beispiel # 1 um php.net/manual/en/function.curl-multi-info-read.php, könnte helfen. Relevante Änderungen werden durch die Kommentare angezeigt.

$urls = array(
    "http://example.com/", 
    "http://qwe.rtyuiop.com/", 
    "http://php.net/" 
); 

$mh = curl_multi_init(); 

foreach ($urls as $i => $url) { 
    $conn[$i] = curl_init($url); 
    curl_setopt($conn[$i], CURLOPT_RETURNTRANSFER, 1); 
    curl_multi_add_handle($mh, $conn[$i]); 
    // Set up info array: 
    $multi_info[(integer) $conn[$i]]['url'] = $url; 
} 

do { 
    $status = curl_multi_exec($mh, $active); 
    $info = curl_multi_info_read($mh); 
    if (false !== $info) { 
     // Add connection info to info array: 
     if (!$info['result']) { 
      $multi_info[(integer) $info['handle']]['error'] = 'OK'; 
     } else { 
      $multi_info[(integer) $info['handle']]['error'] = curl_error($info['handle']); 
     } 
    } 
} while ($status === CURLM_CALL_MULTI_PERFORM || $active); 

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

// Display result messages: 
foreach ($multi_info as $each) { 
    echo $each['url'] . ' => ' . $each['error'] . "\n"; 
} 

/** 
Output: 

http://example.com/ => OK 
http://qwe.rtyuiop.com/ => Could not resolve host: qwe.rtyuiop.com; Host not found 
http://php.net/ => OK 

**/ 

Wenn ein Transferzeit, dann die Meldung für diese URL soll mit dem zu CURLE_OPERATION_TIMEOUTED (int 28), so etwas wie entsprechend seine „Operation Timeout. Die angegebene Timeout-Zeit wurde gemäß den Bedingungen erreicht“ (curl.haxx.se/libcurl/c/libcurl-errors.html).

Verwandte Themen