It may sound a little confused. Let's use several examples to illustrate:
Copy codeThe Code is as follows:
<? Php
Echo 'example :';
Fastcgi_finish_request ();
Echo 'to be, or not To be, that is the question .';
File_put_contents('log.txt ', 'survival or destruction, this is a problem. ');
?>
Use a browser (not a command line !) After running this script, it is found that no corresponding string is output, but the corresponding file is generated. It indicates that after fastcgi_finish_request is called, the client response has ended, but the server script continues to run at the same time!
The rational use of this feature can greatly improve user experience. Let's take another example:
Copy codeThe Code is as follows:
<? Php
Echo 'example :';
File_put_contents('log.txt ', date ('Y-m-d H: I: s'). "Upload video \ n", FILE_APPEND );
Fastcgi_finish_request ();
Sleep (1 );
File_put_contents('log.txt ', date ('Y-m-d H: I: s'). "conversion format \ n", FILE_APPEND );
Sleep (1 );
File_put_contents('log.txt ', date ('Y-m-d H: I: s'). "extract image \ n", FILE_APPEND );
?>
The Code uses sleep to simulate some time-consuming operations. When browsing, the program is not blocked, but all the operations are executed. For details, see the log.
Finally, I will remind you that Yahoo mentioned Flush the Buffer Early in Best Practices for Speeding Up Your Web Site, that is, using the flush method in PHP to send the content to the client as soon as possible, although it is somewhat similar to the fastcgi_finish_request described in this article, it is essentially completely different. Don't confuse it.
Repost Postscript: I have read this method and will send a response and close the connection when calling it. but it will not end the PHP operation. this method is simpler than calling flush or accelerating your Echo.
In addition, from the perspective of code portability, You can include the following code in the Code:
Copy codeThe Code is as follows:
If (! Function_exists ("fastcgi_finish_request ")){
Function fastcgi_finish_request (){}
}
This will not cause problems when the code is deployed in a non-fpm environment.