[英]Running PHP file multiple times in foreach loop
I have an array with 12500 elements (company IDs). 我有一个包含12500个元素的数组(公司ID)。 I need run 1 PHP file for all the elements in the array. 我需要为数组中的所有元素运行1个PHP文件。
Please let me know what is the best way to do that. 请让我知道最好的方法是什么。
I want to use Curl inside the for each loop to execute the file: 我想在每个循环中使用Curl来执行文件:
<?php
$array = ['123','124','125','126','127',......,'12503'];
foreach ($array as &$value) {
$url = 'https://*****/*****/List_daily.php?accountid='.$value.'';
$resp = call_curl($url);
echo $resp."<br>"
/**
Here is where I want to execute the file
**/
}
function call_curl($url){
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => $url,
CURLOPT_TIMEOUT => '5'
));
$resp = curl_exec($curl);
curl_close($curl);
return $resp;
}
?>
您可以尝试并行卷曲请求,以获得更好的性能,您可以将此作为PHP并行卷曲请求的示例
if you don't send any special data to CURL, you can do same easy way with file_get_contents(); 如果你没有向CURL发送任何特殊数据,你可以使用file_get_contents();
if(count($array)) {
$url='https://*****/*****/List_daily.php?accountid=';
foreach ($array as $v) {
$resp = file_get_contents($url.$v);
if($resp) {
echo $resp."<br/>\n"; //or do something
} else {
//error getting data
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.