【发布时间】:2016-01-02 10:36:05
【问题描述】:
我正在使用此代码在 PHP 中进行多卷曲:
$ch1 = curl_init();
$ch2 = curl_init();
// set URL and other appropriate options
curl_setopt($ch1, CURLOPT_URL, 'http://www.example.com/');
curl_setopt($ch1, CURLOPT_HEADER, 0);
curl_setopt($ch2, CURLOPT_URL, 'http://www.example.com/');
curl_setopt($ch2, CURLOPT_HEADER, 0);
//create the multiple 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 handles
do {
$mrc = curl_multi_exec($mh, $active);
} while ($mrc == CURLM_CALL_MULTI_PERFORM);
while ($active && $mrc == CURLM_OK) {
正如您在代码中看到的,我使用curl_multi_add_handle 将两个句柄添加到$mh
无论如何添加句柄 $ch1 和 $ch2 而不重复代码?
通常我会做一个 for 循环 i++ 但这不是一个选项。
所以我正在寻找这样的东西:
curl_multi_add_handle($mh,[$ch1,$ch2]); ??
【问题讨论】: