After chopping hands, the fraud call came before the express delivery was received. How to improve the privacy and security of e-commerce>>>
fastcgi_ finish_ Request () is to flush all response data to the client and end the request. This allows tasks that need a lot of time to continue to run after the client ends the connection
When PHP is running in fastcgi mode, PHP FPM provides a file named fastcgi_ finish_ According to the document, this method can improve the processing speed of the request. If some processing can be done after the page is generated, you can use this method.
it may sound a little confused. Let’s illustrate it with a few examples:
The code is as follows | Copy code |
<?PHP
echo ‘example:’ /* log */ |
Through the browser to access the script, it is found that the corresponding string is not output, but the corresponding file is generated. This shows that when calling fastcgi_ finish_ Request, the client response has ended, but at the same time, the server script continues to run
rational use of this feature can greatly improve the user experience. Strike while the iron is hot: another example:
The code is as follows | Copy code |
<?PHP
echo ‘example:’ file_ put_ Contents (‘log. TXT ‘, date (‘y-m-d H: I: s’)_ APPEND); fastcgi_ finish_ request(); sleep(1); sleep(1); ?> |
in the code, sleep is used to simulate some time-consuming operations. When browsing, the program is not blocked, but it is executed. See the log for details.
finally, to remind you, Yahoo mentioned “flush the buffer early” in the 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, which is similar to fastcgi introduced in this article_ finish_ In addition, in terms of code portability, the following code can be attached to the code:
The code is as follows | Copy code |
if (! function_ exists(“fastcgi_ finish_ request”)) { function fastcgi_ finish_ request() { } } |
Similar Posts:
- Nginx an upstream response is buffered to a temporary file,nginx502 Error
- [Solved] Nginx-FastCGI-“Primary script unknown” while reading response header from upstream,
- Fix Nginx 502 Error:upstream sent too big header while reading response header from upstream
- Shell Syntax Error: operand expected (error token is “-”)
- AttributeError: ‘NoneType’ object has no attribute ‘split’ [How to Solve]
- Solutions to nginx upstream timed out (Two Situations)
- Resource interpreted as Stylesheet but transferred with MIME type text/html: css not work
- [Solved] Primary script unknown in nginx configuration PHP
- Nginx+PHP FastCGI sent in stderr: “Primary script unknown” while reading response head…
- [Solved] HttpClient HttpRequestHeaders.From Error: The specified value is not a valid ‘From’ header string.