PHP curl_multi_exec function
PHP curl_multi_exec function
(PHP 5)
curl_multi_exec - Run Sub current cURL handle connection
Explanation
int curl_multi_exec ( resource $mh , int &$still_running )
Processing in the stack each handle. Whether the handle needs to read or write data can call this method.
parameter
mh
By the curl_multi_init () returns multiple cURL handles.
still_running
A reference to determine whether the operation is still identified executed.
return value
A predefined constants defined in the cURL The cURL code.
Note: This function returns only on the entire batch stack-related errors.A single transmission may still be a problem even when returning CURLM_OK.
Examples
This example will create two cURL handles, add them to handle the batch, and then run them in parallel.
<?php // 创建一对cURL资源 $ch1 = curl_init(); $ch2 = curl_init(); // 设置URL和相应的选项 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); // 创建批处理cURL句柄 $mh = curl_multi_init(); // 增加2个句柄 curl_multi_add_handle($mh,$ch1); curl_multi_add_handle($mh,$ch2); $active = null; // 执行批处理句柄 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); } } // 关闭全部句柄 curl_multi_remove_handle($mh, $ch1); curl_multi_remove_handle($mh, $ch2); curl_multi_close($mh); ?>