"can closing the browser terminate the php script on the server?" Code Answer


PHP won't notice that the browser closed the connection unless it tries to output something (e.g. echo). If it fails to output something, the script will be terminated unless ignore_user_abort is On.

So the script will terminate only if the following conditions are met:

  • the script attempts to output something (because the script won't notice that the user aborted the connection until then)
  • AND php's ignore_user_abort setting is off (if the setting is off, php will terminate the script if fails to output something)

You can avoid the script from terminating by enabling ignore_user_abort.

You can use connection_aborted() at anytime to check is the browser aborted the request.

A script can terminate unexpectedly for other reasons (e.g. max execution time, exception, etc); so you should make use of transactions, so that half-finished changes are canceled if the script terminates abnormally.

By fuck-d12b47a9b1a0 on October 24 2022

Answers related to “can closing the browser terminate the php script on the server?”

Only authorized users can answer the search term. Please sign in first, or register a free account.