Ted
Ted

Reputation: 3885

What happens at the server when a request is made and client quits immediately?

I would like to know what would happen if I have a code like that in a php page doit.php:

$url="http://someServer.com/somepage.php";

$i=10;
while($i--){
getDataFromAnotherServer($url);
}

now, knowing that function getDataFromAnotherServer() can take up to a second or two... What would happen if a user is asking for that doit.php and immediately close the browser ? Would the function still be called 9 times (the loop would reach i==0) or stop somewhere in the middle? Thanks

Upvotes: 2

Views: 201

Answers (2)

encodes
encodes

Reputation: 751

the script would abort. the getDataFromAnotherServer function may take a few seconds im guessing as you don't control the server. this could cause the maximum execution to be reached as well. just something to bare in mind. ignore_user_abort may give the desired result

Upvotes: 0

webbiedave
webbiedave

Reputation: 48887

The script will be aborted (unless there is no attempt to send data to the client during that time). To prevent the script from ending early due to client disconnect, use ignore_user_abort.

More detailed info on PHP connection handling can be found here:

http://www.php.net/manual/en/features.connection-handling.php

Upvotes: 2

Related Questions