aweber/AWeber-API-PHP-Library

API Causing issue when Inserting large number of subscribers from one list to another

Closed this issue · 2 comments

I have got certain requirement to add the existing subscribers from a list to another list , checking some conditions on the way.

But the script is executing too slow and most of the time it is showing " Uncaught exception 'AWeberAPIException' with message 'Rate limit exceeded (API requests per customer account per minute). ". and API connection is disconnected.

For this i also added sleep(10) at the below of the loop to minimize this issue.

  • I have twice used the "find" method to search for a subscriber in a list and added the subscriber to another list if the subscriber is not already existed in the current list.

Any suggestions regarding this.

Hello gaurab:

Sorry for the delay in responding. What your describing is a limitation of the current design of our PHP client library wrapper in how it handles getting throttled.

Fortunately there's a relatively simple work-around that you can use to make your script more responsive.

For the Rate Limit Exceeded errors:

A simple solution is to check for rate limit errors when making an api request in oauth_application.php
and to sleep and retry if you get throttled until you're no longer throttled. This functionality may be implemented in a future version of our client library but it will require developer analysis to ensure that it wouldn't break other developers code. I don't have an ETA on that, but I can certainly walk you thru the idea.

Look at line 132 of oauth_application.php
https://github.com/aweber/AWeber-API-PHP-Library/blob/master/aweber_api/oauth_application.php#L132

You can add your test/retry logic here

When there's an error, $data will be an associative array of the form

array("error"  =>   array(
     "status" => 403, 
     "message" =>  "Rate Limit Exceeded,",
     "type" =>  "RateLimitError",
));

after line 132, just do something like this:

<?php
132 $data = json_decode($response->body, true); 
133 while (( $response->headers['Status-Code'] == 403) && ($data['error']['type'] === 'RateLimitError')) {
134     sleep(5);
135     $response = $this->makeRequest($method, $url, $data);
135     $data = json_decode($response->body, true); 
136 }
?>

This will speed up your script by only sleeping when you need to, rather then every pass thru a loop
and then keep sleeping and retrying until the rate limit clears.

There are also other optimization methods to try to make your script run faster, Could you please provide a code sample of what you're trying to do. If you prefer not to post it publicly, feel free to contact us through the support widget on labs.aweber.com or by emailing api@aweber.com.

Let me know if this helps the problem you're experiencing.

  • Ed
jon9 commented

Should the following code sleep time be set to 60 sec opposed to 5 sec?

body, true); 133 while (( $response->headers['Status-Code'] == 403) && ($data['error']['type'] === 'RateLimitError')) { 134 sleep(5); 135 $response = $this->makeRequest($method, $url, $data); 135 $data = json_decode($response->body, true); 136 } ?>