0

I need to loop and inside I need to call curl through a function. How do I call this function without losing performance (decrease script execution time which is around 2.23 sec)? Thanks.

foreach ($token_values as $token) {
    $cards[] = array_merge(array('CardToken' => $token), getCards($merchantId, $merchantKey, $token));
}

function getCards($merchantId, $merchantKey, $token){
   $ch = curl_init('https://xxxxxxxxxxxxxx/1/card/'.$token);
   $headers = array('Content-Type: application/json', 'MerchantId: ' . $merchantId, 'MerchantKey: ' . $merchantKey);
   curl_setopt($ch, CURLOPT_HTTPHEADER, $headers );
   curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
   $result = curl_exec($ch);
   curl_close($ch);
   return json_decode($result, true);
}
afazolo
  • 382
  • 2
  • 6
  • 22

0 Answers0