下面有一个php curl请求脚本,其中包含很多请求,可能会大大减慢代码的速度,需要1-2分钟才能加载。查看curl_multi_execute但无法找到可行的解决方案。任何支持非常赞赏
$curl = curl_init();
$options = array(
'Access-Token: '. ACCESS_TOKEN .'',
'Client-Secret: '. CLIENT_SECRET .'',
'Content-Type: '. CONTENT_TYPE .'',
'Accept: '. ACCEPTS .''
);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, $options);
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $requestMethod);
$cyfin=$row['CYfin'];
curl_setopt($curl, CURLOPT_URL, ENDPOINT . "accounts");
$data = json_decode(curl_exec($curl),true);
$curl2 = curl_init();
curl_setopt($curl2, CURLOPT_HTTPHEADER, $options);
curl_setopt($curl2, CURLOPT_RETURNTRANSFER,true);
for ($x = 1; $x <= $data['MetaInformation']['@TotalPages']; $x++) {
curl_setopt($curl, CURLOPT_URL, ENDPOINT . 'accounts/?page='.$x);
$data2 = json_decode(curl_exec($curl),true);
foreach ($data2["Accounts"] as $i => $account) {
if($account["Active"] = 1){
$accountnumber = $account["Number"];
$accountname = $account["Description"];
curl_setopt($curl2, CURLOPT_URL,ENDPOINT . 'accounts/'.$accountnumber.'?financialyeardate='.$row['CYfin']);
$data2 = json_decode(curl_exec($curl2),true);
print_r($data2);
}
}
}
curl_close($curl);
curl_close($curl2);