That sounds like you’re making too many requests too quickly and being throttled.
Depending on what’s happening, I would look to see if any of your actions could be passed off to an automation (a.k.a. Camapign), and reduce the number of API calls being made.
If that’s not possible you need to add delays between your API calls.
Take a look at these PHP functions:
- sleep() - Delay execution
- usleep() - Delay execution in microseconds
- time_nanosleep() - Delay for a number of seconds and nanoseconds
Decide which method fits your needs, I prefer usleep() over sleep() and I have not used the time_nanosleep(), but any of those methods will let you delay execution between API requests, and help to avoid throttling.
You may also need to use:
set_time_limit() - Limits the maximum execution time
… depending on how long you have to delay the script execution or your server could timeout the request.