user3849602
user3849602

Reputation:

Does curl_exec() retry if timeout?

In my application I have to make a POST call to a webservice. They send me an XML response, basically saying "Accepted" or "Refused".
Last week I had an issue with one of these calls: I received a "Refused" response while their backend was telling me this request had been accepted.
I asked them what happened and they told me they received 2 requests (with the same ID - a parameter I send to them). First one was "Refused", second one was "Accepted".

I investigated: in my code, if I receive a "Refused" response, I log it, I update my database, and that's it. I do not try again.

The only thing would be PHP curl functions.
The day the problem occured, the webservice took unusual long time to response (20 seconds).
Could curl have made several calls? There is no retry option in the PHP function (or I didn't find it), but I'd rather ask here to be sure.

Here is my curl code.

$ch = curl_init();

$myArrayWithDatas = array( '...' );
$httpQueryFields = http_build_query($myArrayWithDatas);

$url = "https://www.webservice.com/api";
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $httpQueryFields);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);

if (empty($response)) {
    // I log an error
    // (no trace of that in my logs)
} else {
    // I log the XML response
    // (one "Refused" response logged)
}

curl_close($ch);

Is there any case where this code could send 2 or more requests to the $url?

Upvotes: 1

Views: 2203

Answers (1)

alfallouji
alfallouji

Reputation: 1170

curl_exec will only do 1 call.

Are you running your code via a cron job or scheduled task ? If that's the case, maybe your code has been launched twice and that would explain why there were two calls done.

Upvotes: 2

Related Questions