Easy Tutorial
❮ Func Filesystem Is Uploaded File Php Gettype Function ❯

PHP curl_multi_exec Function

PHP cURL Reference Manual

(PHP 5)

curl_multi_exec — Run the sub-connections of the current cURL handle


Description

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

Processes each handle in the stack. This method can be called whether the handle needs to read or write data.


Parameters

mh

The cURL multi handle returned by curl_multi_init().

still_running

A reference to a flag to tell whether the operations are still running.


Return Value

A cURL code defined in the cURL predefined constants.

Note: This function only returns errors regarding the entire batch stack. Individual transfers may have issues even when CURLM_OK is returned.


Example

This example will create two cURL handles, add them to a batch handle, and run 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://lxr.php.net/");
curl_setopt($ch1, CURLOPT_HEADER, 0);
curl_setopt($ch2, CURLOPT_URL, "http://www.php.net/");
curl_setopt($ch2, CURLOPT_HEADER, 0);

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

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

$active = null;
// Execute the batch handle
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 all the handles
curl_multi_remove_handle($mh, $ch1);
curl_multi_remove_handle($mh, $ch2);
curl_multi_close($mh);

?>

PHP cURL Reference Manual

❮ Func Filesystem Is Uploaded File Php Gettype Function ❯