Easy Tutorial
❮ Func Xml Utf8 Encode Func Misc Die ❯

PHP curl_multi_add_handle Function

PHP cURL Reference Manual

(PHP 5)

curl_multi_add_handle — Add a single cURL handle to a cURL multi session


Description

int curl_multi_add_handle ( resource $mh , resource $ch )

Adds the ch handle to the multi session mh


Parameters

mh

A cURL multi handle returned by curl_multi_init().

ch

A cURL handle returned by curl_init().


Return Values

Returns 0 on success, or one of the CURLM_XXX error codes on failure.


Example

This example will create two cURL handles, add them to a multi handle, and then execute them in parallel.

<?php
// Create a pair of cURL resources
$ch1 = curl_init();
$ch2 = curl_init();

// Set URL and other appropriate options
curl_setopt($ch1, CURLOPT_URL, "http://www.w3cschool.cc/");
curl_setopt($ch1, CURLOPT_HEADER, 0);
curl_setopt($ch2, CURLOPT_URL, "http://www.php.net/");
curl_setopt($ch2, CURLOPT_HEADER, 0);

// Create a multi cURL handle
$mh = curl_multi_init();

// Add the two handles
curl_multi_add_handle($mh, $ch1);
curl_multi_add_handle($mh, $ch2);

$running = null;
// Execute the handles
do {
    curl_multi_exec($mh, $running);
} while ($running > 0);

// Close all the handles
curl_multi_remove_handle($mh, $ch1);
curl_multi_remove_handle($mh, $ch2);
curl_multi_close($mh);
?>

PHP cURL Reference Manual

❮ Func Xml Utf8 Encode Func Misc Die ❯