Reputation: 1261
I'm running an ajax request to a via jQuery which has a timeout of 10000 (i.e. 10 seconds). The ajax request calls a local PHP script and in the script I have a cURL request to an external site with its own timeout of 30 seconds. Suppose my ajax request takes 8 seconds, and then my cURL request takes 4 seconds. Will my original ajax request throw an error? Or will the original ajax request only throw an error if it takes more than 10 seconds to connect to my local script?
Upvotes: 1
Views: 412
Reputation: 5157
The AJAX call timeout would trump any timeout you set in PHP so basically AJAX would timeout or "throw an error" after 10 seconds even though your script would continue running for 30 seconds as you gave in your example.
It's important to note that any processing that happens in your PHP script (Emailing, Database Calls) would continue to happen even though AJAX has timed out but since AJAX has timed out nothing would display on your browser.
Ideally you would want to adjust your code so the two timeouts are similar as it could cause unexpected behavior. For example, users clicking on a button multiple times after thinking there was a failure and having multiple emails or database inserts occur).
Upvotes: 1
Reputation: 2975
f you have some kind of timeout, it will be called after the time set, So in your case, 10s. Your full request AJAX + cURL must be less than this time.
But the best way to use asynchronous task would be to use callback or promise, so this way you can wait to have a result before updating a view
Upvotes: 2