Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What happens to canceled requests to a PHP page?

Tags:

php

When a long-running PHP file is executing, and the user cancels the page request in their browser midway, is the rest of the script ran on the server?

like image 501
Yoshiyahu Avatar asked Dec 08 '11 06:12

Yoshiyahu


1 Answers

PHP normally terminates script execution once it realizes that the connection is closed:

PHP will not detect that the user has aborted the connection until an attempt is made to send information to the client. Simply using an echo statement does not guarantee that information is sent, see flush().

You can keep your script running using ignore_user_abort().

Also, there is a default time limit for which scripts are allowed to run. You may want to override that using set_time_limit().

like image 54
nsanders Avatar answered Nov 09 '22 06:11

nsanders