It may sound a little confusing, let’s illustrate it with a few examples:
Copy code The 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 destroy, that's the question. ');
?>
Run this script through the browser (not the command line!) and found that the corresponding string is not output, but The corresponding files are generated. This shows that after calling fastcgi_finish_request, the client response has ended, but at the same time the server script continues to run!
Proper use of this feature can greatly improve the user experience. Here is another example:
Copy the code The code is as follows:
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') . "Convert format n", FILE_APPEND);
sleep(1);
file_put_contents('log.txt', date('Y-m-d H:i:s') . "Extract picture n", FILE_APPEND);
?>
Sleep is used in the code to simulate some time-consuming operations. The browsing is not blocked, but the programs are executed. See the log for details.
Finally, let me remind you, Yahoo mentioned Flush the Buffer Early in Best Practices for Speeding Up Your Web Site, which is to use the flush method in PHP to send the content to the client as soon as possible, although on the surface it is the same as The fastcgi_finish_request introduced in this article is slightly similar, but it is completely different in nature, so don’t get confused.
Reprint PS: I took a look at this method. When called, a response will be sent and the connection will be closed. But it will not end the running of PHP. Compared with calling flush, or what I introduced before, it will speed up your For Echo, this method is simpler.
In addition, in terms of code portability, you can attach the following code to the code:
Copy Code The code is as follows:
if (!function_exists("fastcgi_finish_request")) {
function fastcgi_finish_request() { }
}
Won’t cause code deployment problems in non-fpm environments.
http://www.bkjia.com/PHPjc/323231.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/323231.htmlTechArticleIt may sound a little confusing. Let’s illustrate it through a few examples: Copy the code as follows: ?php echo ' Example: '; fastcgi_finish_request(); echo 'To be, or not to be, that...