Matthew Fournier
Matthew Fournier

Reputation: 1155

PHP max_execution_time and multiple consecutive AJAX calls

So, I know that max_execution_time will limit the length of time a single php script can run on the server, but what I wonder is if I have a script that calls another through ajax, are they considered one script or two for the purposes of this?

For example, if I have a checkout.php that takes, let's say 10 seconds to run, and inside of it is an ajax call to a submit_payment.php that takes 20 more seconds, would this stop if max_execution_time is set to something smaller than 30?

Expanding on this, if, after submit_payment.php fully resolves and returns back to checkout.php, can I then ajax to a third php file that takes another 10 seconds?

Basically, is max_execution_time going to be checked on (10 + 20 + 10) or will it be checked to each of these individually?

Upvotes: 0

Views: 870

Answers (1)

Ray
Ray

Reputation: 41428

AJAX requests happen on the client in javascript, not in PHP. Once you return to the client and it begins to process the HTML to parse and act on javascript to say make an AJAX call, the initial php request is finished. The AJAX reques results in a fresh, new HTTP request to be handled by a PHP script.

PHP is stateless. Each request (regular or ajax) is treated as separate script run for max_execution_time. As long as each request runs under the limit, you can string any number of them together in a series of requests.

Upvotes: 2

Related Questions