
The short answer: when a request to an API times out, you do not know whether it got through. It may have failed before leaving, or been carried out on the other side with the reply lost on the way back. Retrying blindly is how a customer gets charged twice or the same SMS goes out twice. The defence has a name, idempotency: making a repeated request have the same effect as doing it once. This is for developers connecting a site to payments, SMS or any API that creates things.
When to retry, and when not to
| What happened | Retry? | How |
| The name does not resolve or the connection was refused (cURL error 6 or 7) | Yes | The request never left. See cURL errors 28, 7 and 6. |
| Timed out (error 28) or the connection dropped halfway | Only with care | You do not know whether it was done. Check the status first, or retry with the same idempotency key. |
| 429 Too Many Requests | Yes, later | Wait for whatever the Retry-After header says. See error 429. |
| 500, 502, 503 or 504 | Usually yes | With longer and longer waits and, if the request creates or charges something, with an idempotency key. |
| 400, 401, 403, 404 or 422 | No | The request is wrong or not allowed. Retrying gives the same error: fix it first. |
| 409 Conflict | It depends | In many APIs it means “already exists” or “already in progress”. Check before doing anything else. |
| 200 or 201 | No | It is done. Keep the response. |
Making a charge safe to retry
|
|
|
|
|
|
| The “Pay” button repeats too. The customer clicks twice, or goes back and resubmits the form. Disable the button after the first click, but do not rely on that alone: on the server, use the same order reference so the second request runs into the first instead of creating another charge. |
| Log every attempt with its reference, time, status code and cURL error. When a customer says “I was charged twice”, that log shows whether there were two charges or one retry the API ignored. See also calling a web API from PHP. |
|
Requests from your site to an API keep timing out? Tell us the API’s address and the time of one case, and we will check whether the hosting’s outgoing connection plays a part. Open a support ticket |
RECOMMENDED PRODUCT Web hosting with cPanel Domain and SSL included, daily backups and the panel you already know. from 321,75 MT/mo (3-year plan, with coupon) See plans |











