PHP需要同时批量请求多个URL时,可以使用curl_multi实现并发请求。
public static function rolling_curl($urls, $postData=array(),$custom_options = null){
//多个url访问
if (sizeof($urls)==0) return;
// make sure the rolling window isn't greater than the # of urls
$rolling_window = 8;
$rolling_window = (sizeof($urls) < $rolling_window) ? sizeof($urls) : $rolling_window;
$master = curl_multi_init();
$curl_arr = array();
// add additional curl options here
$std_options = array(
CURLOPT_RETURNTRANSFER => true,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_MAXREDIRS

本文介绍了一种使用PHP的curl_multi函数实现多个URL并发请求的方法。通过滚动窗口的方式,该方法能够有效地提高请求处理效率,特别适合需要批量处理大量HTTP请求的场景。
最低0.47元/天 解锁文章
719

被折叠的 条评论
为什么被折叠?



