downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | conferences | my php.net

search for in the

curl_multi_remove_handle> <curl_multi_info_read
[edit] Last updated: Fri, 17 May 2013

view this page in

curl_multi_init

(PHP 5)

curl_multi_initGibt einen cURL-Multi-Handle zurück

Beschreibung

resource curl_multi_init ( void )

Erlaubt die parallele Verarbeitung mehrerer cURL-Handles.

Parameter-Liste

mh

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

Rückgabewerte

Gibt im Erfolgsfall ein cURL-Handle zurück, andernfalls FALSE.

Beispiele

Beispiel #1 curl_multi_init()-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://www.example.com/");
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);

$running=null;
// Handles ausführen
do {
    
usleep(10000);
    
curl_multi_exec($mh,$running);
} while (
$running 0);

// Handles schliessen
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_init - [2 notes]
up
-2
hushuilong at gmail dot com
1 year ago
Simulate multiple threads request:
<?php
function multiple_threads_request($nodes){
       
$mh = curl_multi_init();
       
$curl_array = array();
        foreach(
$nodes as $i => $url)
        {
           
$curl_array[$i] = curl_init($url);
           
curl_setopt($curl_array[$i], CURLOPT_RETURNTRANSFER, true);
           
curl_multi_add_handle($mh, $curl_array[$i]);
        }
       
$running = NULL;
        do {
           
usleep(10000);
           
curl_multi_exec($mh,$running);
        } while(
$running > 0);
       
       
$res = array();
        foreach(
$nodes as $i => $url)
        {
           
$res[$url] = curl_multi_getcontent($curl_array[$i]);
        }
       
        foreach(
$nodes as $i => $url){
           
curl_multi_remove_handle($mh, $curl_array[$i]);
        }
       
curl_multi_close($mh);       
        return
$res;
}
print_r(muti_thread_request(array(
   
'http://www.example.com',
   
'http://www.example.net',
)));
?>
up
-3
jaisen at jmathai dot com
5 years ago
http://github.com/jmathai/epicode/tree/master/php/EpiCurl.php

If you fire off 10 curl requests in parallel you don't have to wait for all of them to be finished before accessing one which is already finished.

 
show source | credits | stats | sitemap | contact | advertising | mirror sites