Easy Tutorial
❮ Func Array Udiff Uassoc Func Array Replace Recursive ❯

PHP curl_multi_init Function

PHP cURL Reference Manual

(PHP 5)

curl_multi_init — Returns a new cURL multi-handle


Description

resource curl_multi_init ( void )

Allows the handling of multiple cURL handles in parallel.


Parameters

This function has no parameters.


Return Values

Returns a cURL multi-handle on success, or FALSE on failure.


Examples

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

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

// Set the URL and corresponding options
curl_setopt($ch1, CURLOPT_URL, "http://www.example.com/");
curl_setopt($ch1, CURLOPT_HEADER, 0);
curl_setopt($ch2, CURLOPT_URL, "http://www.php.net/");
curl_setopt($ch2, CURLOPT_HEADER, 0);

// Create a multi-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 multi-handle
do {
    usleep(10000);
    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 Array Udiff Uassoc Func Array Replace Recursive ❯