After the user closes the browser, will the server proceed?

Source: Internet
Author: User
The user clicks the page link to initiate a request. if the background processing time is too long, after the user closes the browser directly, will the server-side programs continue to be executed? If it is executed, how can it be automatically terminated after the user closes the browser? The user initiates an ajax request, and the server executes the request for a long time...
  1. The user clicks the page link to initiate a request. if the background processing time is too long, after the user closes the browser directly, will the server-side programs continue to be executed? If it is executed, how can it be automatically terminated after the user closes the browser?
  2. When a user initiates an ajax request, the server executes the request for a long time. how does the backend terminate the request when the user abortion is an ajax request?
  3. In view of the http stateless protocol, is it because the server does not know when the user closes the browser or cancels the ajax request, but continues to execute it? Do I need to write a program in the background to handle such a problem?

Reply content:
  1. The user clicks the page link to initiate a request. if the background processing time is too long, after the user closes the browser directly, will the server-side programs continue to be executed? If it is executed, how can it be automatically terminated after the user closes the browser?
  2. When a user initiates an ajax request, the server executes the request for a long time. how does the backend terminate the request when the user abortion is an ajax request?
  3. In view of the http stateless protocol, is it because the server does not know when the user closes the browser or cancels the ajax request, but continues to execute it? Do I need to write a program in the background to handle such a problem?

  1. The browser initiates a request and then the serverStartRunServer step-by-step operation completedOrExceptionOrTIMEOUT. The browser cannot close the server.

    But ......

  2. The technology is always not quite developed. rfc http 1.1 defines the Connection response header. for details, refer to PHP Connection processing.

  3. Http stateless protocolThis is a legacy issue. The current HTTP version is also solving this issue, such as the long link mentioned above. Define the Connection in RFC2616 (HTTP 1.1.

Further reading: http protocol Learning Series

Yes, so nginx adds an http code: 499, indicating that the client is disconnected.

After the server software detects a request, it will probably establish a thread to process the request. It first reads data from the stream, parses the request header, then delivers it to the interpreter of a language, retrieves the data, and writes the data back.

If the user closes the browser, the browser closes the stream in advance, which is equivalent to writing an EOF to the stream. The server will certainly execute it down, because it still needs to write logs or something, but it does not perform stream operations when it reads the EOF.

I don't know whether you are talking about PHP, nginx, apache, or fastcgi, and how to configure the front-end proxy. The processing methods of each server container are different. do not take the experience as an experiment. Write a PHP file, while endless loop, append the current time to a file every 1 second in sleep, access the browser, and then close it to see if the file continues to be written.

My impression is that the browser is closed and PHP on the server will not be executed, so PHP will have the ignore_user_abort () function, ignoring the user's behavior of turning off the browser and letting the server execute this script.

This is not easy to control. timeout is performed on the server.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.