(PHP 5)
curl_multi_exec — run a sub-connection of the current cURL handle
int curl_multi_exec ( resource $mh , int &$still_running )
Process each handle on the stack. This method can be called whether the handle needs to read or write data.
mh
cURL multiple handles returned by curl_multi_init().
still_running
A reference to an identifier used to determine whether the operation is still being performed.
A cURL code defined in the cURL predefined constants.
Note: This function only returns errors related to the entire batch stack. There may still be problems with individual transfers even when CURLM_OK is returned.
This example will create 2 cURL handles, add them to a batch handler, 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 batch cURL handle $mh = curl_multi_init();//Add 2 handles curl_multi_add_handle($mh ,$ch1);curl_multi_add_handle($mh,$ch2);$active = null;//Execute 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 handles curl_multi_remove_handle($mh, $ch1);curl_multi_remove_handle($mh, $ch2);curl_multi_close($mh);?>