What happens when I click the Stop button on the browser?

后端 未结 5 1992
生来不讨喜
生来不讨喜 2020-12-29 22:16

Let\'s say I click a button on a web page to initiate a submit request. Then I suddenly realize that some data I have provided is wrong and that if it gets submitted, then I

5条回答
  •  被撕碎了的回忆
    2020-12-29 22:45

    Since this question may attract attention for people not using Java, I thought I would mention PHPs behavior in regard to this question, since it is very surprising.

    PHP internally maintains a status of the connection to the client. The possible values are NORMAL, ABORTED and TIMEOUT. While the connection status is NORMAL, life is good and the script will continue to execute as expected.

    If the user clicks the Stop button in their browser, the connection is typically closed by the client and the status changes to ABORTED. A change of status to ABORTED will immediately end execution of the running script. As an aside, the same thing happens when the status changes to TIMEOUT (PHPs setting for the allowed run-time of scripts is exceeded).

    This behavior may be useful in certain circumstances, but there are others where it could be problematic. It seems that it should be safe to abort at any time during a proper GET request; however, aborting in the middle of a request that makes a change on the server could lead to only partially completed changes.

    Check out the PHP manual's entry on Connection Handling to see how to avoid complications resulting from this behavior:

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

提交回复
热议问题