When PHP is running in fastcgi mode, PHP FPM provides a method called Fastcgi_finish_request. As the document says, this method can increase the processing speed of requests, which can be used if some processing can be done after the page has been generated.
Example
Echo ' Fastcgi_finish_request test '; fastcgi_finish_request (); /* */echo ' request end '; // will not be output /* */ile_put_contents (' log.txt ', ' Survival or destruction, this is a question ');
This script is accessed through a browser, and the result is that the corresponding string is not output, but the corresponding file is generated. This means that after calling Fastcgi_finish_request, the client response is over, but the server script continues to run!
Reasonable use of this feature can greatly enhance the user experience:
Example
Echo ' Fastcgi_finish_request test 'file_put_contentsdate(' y-m-d h:i:s '). "Upload video \ n",sleep(1); file_put_contents Date (' y-m-d h:i:s '). "Convert format \ n",sleep(1); file_put_contents Date (' y-m-d h:i:s '). "Extract picture \ n", file_append);
The code uses sleep to simulate some time-consuming operations, browsing without being blocked, the program is executed, the specific look at the log.
Disadvantages of the Fastcgi_finish_reques () function:
1.PHP FastCGI process is limited, processing the php-cgi process of asynchronous operation, unable to process the new request;
2. If the number of concurrent accesses is large, the php-cgi process is full, and the new access request is not php-cgi to be processed. Nginx server will appear: 502 Bad Gateway.
Use Fastcgi_finish_request to improve page response speed