I have integrated five shipping APIs like UPS, FEDEX, PUROLATOR, TNT, CANADA POST into my website in simple PHP. I send HTTP request, and request return in xml format to get shipping rates. I have created classes for each API and created functions to set login and dimensions parameter dynamically...as following
<?php
if($sub){
$canadaPostRate->setCredentials($CPC_number,$length,$width,$height,$weight,$from,$to);
$fedexRate->setCredentials($user,$key,$account_number,$shipping_number,$weight,$height,$width,$length,$from,$to);
// similary for all other API
}
?>
I have got response from these API correctly but the problem is that it takes too long like it takes minimum 1.5 min to show output. Is there any solution to minimize response time?
One thing comes to mind (if it's for presentation): don't do 5 external API calls in one request. Use AJAX requests to get the shipping rates individually. Right now, you're waiting for CanadaPost to respond before querying FedEx. If you use 5 different requests, you'll not be waiting for one to finish before starting the other.
But really it's impossible to say without more information. Have you done any tracing on your code to see where the delay is? Is it really just the HTTP request? Is it the way you parse the data? Is it a database connection that's slow? Start logging, with time in milliseconds, at various points in your api calls, such as right before the HTTP request, right after, right before returning the data etc.
You could also use another shipping API to handle these calls all at once. Something like EasyPost or Postmaster?