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...
- 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?
- 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?
- 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:
- 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?
- 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?
- 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?
The browser initiates a request and then the serverStartRunServer step-by-step operation completedOrExceptionOrTIMEOUT. The browser cannot close the server.
But ......
The technology is always not quite developed. rfc http 1.1 defines the Connection response header. for details, refer to PHP Connection processing.
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.