Haven't written a blog for a long time, because there is nothing to write.
The reason why this question, because read a Daniel article: PHP upgrade caused by high system load problem analysis. After reading, some of the text triggered my idea, also want to verify.
Scheme, grab the packet with tcpdump, get the system call with Strace
8080 9000 0 -w Temp
8080 is the Nginx service port, 9000 is the port of the PHP-FPM service, grasping these two ports is to see the browser, Nginx, php-fpm interaction between the three. After grasping the package, use Wireshark analysis, as follows:
tcp.port==46540
The above statement is the filter syntax for Wireshark, which is used to filter the packages we are interested in
The explanations are as follows:
1,46540 is the port of the browser, Http-alt is nginx,54352 is the port of Nginx request PHP-FPM, Cslistener is PHP-FPM
2, because all of my operations are on a single machine, including browser access, so all IP is 127.0.0.1
3,
A: The first part of the figure, representing the browser and Nginx three times the handshake process.
B: The second part of the figure, on behalf of the browser request a URL to nginx.
C: The third part of the figure represents the three-time handshake process between Nginx and PHP-FPM.
D: In the fourth part of the diagram, the browser's request is forwarded to PHP-FPM on behalf of Nginx.
E: The fifth part of the 11,13,14 line, on behalf of the browser to actively close the connection between the Nginx. Why off, because I constantly refresh the page, in the second refresh, the browser will close the last request.
Why is it three times off instead of four handshake shut down? Because the 13th line is actually two packages to synthesize a package sent, this should be calculated as TCP optimization bar.
F: The fifth part of the figure of 12, 25 lines, on behalf of Nginx to close the browser connection message, told the PHP-FPM.
G: The sixth part of the figure, through the left time can be found, is 5 seconds after the PHP-FPM attempt to return to nginx it 縇 dyed page, but Nginx directly reset dropped the connection.
Why return after 5 seconds, because I'm in the first line of the PHP program, Sleep (5), to simulate the long-time business logic processing.
Analysis here, the conclusion is already very obvious, is:
After the browser closes the request, the Nginx notifies the PHP-FPM, but PHP-FPM ignores the notification and continues processing until the processing results are sent, only to know that the connection has been closed.
I think here, PHP-FPM still have the space to optimize.
You can look at the results of the strace, you can also verify the above conclusions.
PHP-FPM The page is being generated, will PHP-FPM exit when the browser refreshes?