我有以下CURL代码:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "websiteURL");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("
Content-Type: application/json",
'Authorization: Basic '. base64_encode("XXXXX:YYYYYY")
));
for ($i=0; $i < 300; $i++){
curl_setopt($ch, CURLOPT_POSTFIELDS, '{"src": "'.$numbers_from[$i] ['number_from'].'","dst": "'.$messages[$i['international_format'].'", "text": "'.$current_message.'"}');
$message = curl_exec($ch);
}
curl_close();
如何使用Multi CURL?使用多个CURL的这些函数有哪些替代方法?
答案 0 :(得分:0)
取自docs
的示例<?php
// create both cURL resources
$ch1 = curl_init();
$ch2 = curl_init();
// set URL and other appropriate 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 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) {
if (curl_multi_select($mh) != -1) {
do {
$mrc = curl_multi_exec($mh, $active);
} while ($mrc == CURLM_CALL_MULTI_PERFORM);
}
}
//close the handles
curl_multi_remove_handle($mh, $ch1);
curl_multi_remove_handle($mh, $ch2);
curl_multi_close($mh);
?>