Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Guzzle's requestAsync() and \GuzzleHTTP\Pool for API write requests #65

Open
torgospizza opened this issue Oct 3, 2017 · 0 comments

Comments

@torgospizza
Copy link

torgospizza commented Oct 3, 2017

According to MailChimp API Best Practices, they recommend that API calls be made as async background processes. This is to avoid times when the user might experience a long wait, as a response is expected from the MC API that might take a few seconds.

Currently this Guzzle HTTP library implementation uses request() exclusively, and as such all requests including Update and Create, are done synchronously, which means the end user will be required to wait for the response and its result. This leads to poor user experience, and in my case, I was seeing GuzzleHTTP reporting open connections of 15 seconds to the API. (This might be fixable just by adding Connection: close to our headers array, too; however I think there are advantages to persistent connections, and even better performance can be gained when used in conjunction with background tasks.)

I recognize we can also use batch requests to help improve performance, but those requests still rely on user interaction and result in a blocking call to the external resource (MailChimp). I've seen some requests in the MC Dashboard reported as taking 3-5 seconds to process, which for an e-commerce site is a potentially problematic amount of time to wait.

Therefore, any non-read requests to the API (PUT, POST, PATCH) should create or merge with a \GuzzleHttp\Pool instance, which in turn calls requestAsync(), thereby allowing the MC API PHP library to handle updating and creation of carts and orders without blocking user requests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant