I am using google finance calculator to convert currency. I have to convert atleast = 2000 numbers to be converted at once. Below I have set only 10 numbers in the array. When I run this code, it is working fine but it is taking too much time. When I try with around 5000 numbers, it sometimes time out error. Can anybody help me how can I modify with my code for large number of datas. Thank you. Below is code that I am currently using.
$amounts= array(10, 20, 30, 40, 50, 60, 70, 80, 90, 100);
$from_Curr ='USD';
$to_Curr = 'THB';
$convertedCurrency = convertCurrency($amounts, $from_Curr, $to_Curr);
print_r($convertedCurrency);
function convertCurrency($amounts= array(), $from, $to){
$convertedCurrency = array();
foreach ($amounts as $amount) {
$url = "https://www.google.com/finance/converter?a=$amount&from=$from&to=$to";
$data = file_get_contents($url);
preg_match("/<span class=bld>(.*)<\/span>/",$data, $converted);
$converted = preg_replace("/[^0-9.]/", "", $converted[1]);
array_push($convertedCurrency, round($converted, 3));
}
return $convertedCurrency;
}