It may sound a little confusing, let's illustrate it with a few examples:
Copy code The code is as follows:
echo 'Example:';
fastcgi_finish_request();
echo 'To be , or not to be, that is the question.';
file_put_contents('log.txt', 'To be or not to be, that is the question.');
?>
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);
? >
The code uses sleep 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 different from this article The introduced fastcgi_finish_request is slightly similar, but essentially completely different, so don’t get confused.
Repost P.S.: 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 speeding up your Echo as I introduced before, this method The method can be simpler.
In addition, from the perspective of code portability, you can attach the following code to the code:
Copy the code The code is as follows:
if (!function_exists("fastcgi_finish_request") ) {
function fastcgi_finish_request() { }
}
The above introduces the magical fastcgi_finish_request in fastcgi php, including fastcgi content. I hope it will be helpful to friends who are interested in PHP tutorials.