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?
Related
I`m working on application which prviding clients to use calendar and creating some events there (I mean calendar in my app). Some of clients are have more than 1000 events in calendar and I want to start using Google Calendar . But I cant find any way to send multiple events in Google Calendar by 1 request.
Question: Is it possible to send few events in 1 request by using php-sdk, which google provides or by any other way such a http request?
Upd: I saw batch requests in google calendar docs, but Im not sure that its working now and how do I need to use it
Thanks!
The method you would be using is events.insert this method Creates an event as in singular there is no way to send a request that would send more than one.
You could use batching but all batching really is is sending X number of event.inserts in a single batch request. Its not going to save you on quota the quota cost will be the same the only thing it will save you on is on the number of HTTP calls you are making.
Global HTTP Batch Endpoints (www.googleapis.com/batch) will cease to work on August 12, 2020 as announced on the Google Developers blog. For instructions on transitioning services to use API-specific HTTP Batch Endpoints (www.googleapis.com/batch/api/version), refer to the blog post.
The above statment does not mean that batching doesnt work. It just means that the old batching endpoint which worled for every API no longer works now you need to send batching requests to each api
www.googleapis.com/batch/drive/v3
www.googleapis.com/batch/calendar/v3
you used to be able to send all batching requests no matter what api you were working with to
www.googleapis.com/batch
That no longer works.
I'm getting the reach metrics via api call
{page-id}/fields=insights.metric(post_impressions){values}
But didn't find any way to get reach metric of facebook posts using webhook.
Do we get reach metrics using below endpoint
$facebook_page_id.'/subscribed_apps?subscribed_fields=feed
I'm following enter link description here
But didn't find any way to get reach metric of facebook posts using webhook.
There isn’t any.
The data you can get from this endpoint, is not data that would require any reaction “in real time” to begin with, so it would make rather little sense to integrate this into web hooks in the first place.
And these insight metrics get updated once a day only anyway, AFAIK.
Just make the API request, when you need the insights data.
I am trying to develop site like insurance but I am stuck at one position like after taking input data from user I want to pass those input to multiple different external api and get those all api response on to page but if one of api response fails whole process fails and I also don't want to user to wait for too long. I was thinking of doing with queue but don't how to get response from queue. I even try to set up gearman but it's too complicated to work on. Any help would be appreciated..
You can give a try with Queue Job chaining..so that ur jobs will get dispatched sequentially..
To get ACK for API is being failed or success, create an callback API which will be hit when your queue object is dispatched with required statues..and can write logic whatever you are willing to.
I hope this will help to some extent..
I need to push offline transactions to Google Analytics.
I am thinking of creating a php script that queries the ecommerce database looking at transactions made in the last hour created from the backend. Having identified these transactions (and line items/SKU's).
How do I use PHP to push data to Google Analytics?
You need to go though the measurement protocol. There is no client library to help you do this in PHP you will have to code it yourself. That being said its not that hard its just a normal HTTP Post or HTTP Get request. The trick is building up your requests correctly.
A couple of quick tips.
Qt stands for que time and will allow you to set the time that the hit arrived on your server. Note it must not be greater than four hours ago.
While you are testing this you can use the debug endpoint to validate your hits. The hits wont be sent to Google but it will tell you if they are valid or not.
Measurement Protocols as #DaImTo mentioned is the answer. make a try here replacing the UA Id -
https://ga-dev-tools.appspot.com/hit-builder/?v=1&tid=UA-XXXXX-Y&cid=555&t=transaction&ti=12345&ta=westernWear&tr=50.00&ts=32.00&tt=12.00&cu=EUR
You can use DIv tool to validate all your post requests.
(dont forget to enable - ecommerce from view settings in GA when testing on new account)
I have a new question. This is my context:
I want to make my own API REST, where I can call this method with information about my product as parameters. My backend method do the typical purchased process but it doesn't show the PayPal screen which show information about my product, just do the process directly and I receive an answer. Is it possible?
I'm using the PayPal SDK for PHP, and looking for at Google I just have gotten that the PayPal page shows, but I'm new in this. Your answer will be so good!
Yes, this is very possible. There are plenty of tutorials online for building your own REST service, and within your service methods you can hit other APIs or do anything you need to do.
Your service can parse the results from the 3rd party service you're hitting (you could hit 10 different services if you wanted to) and then you would generated your own basic response which includes a collection of all that data back to whatever client hits your service.