The fastcgi_finish_request function costs most of the runtime

I built a site with yii + php-fpm + nginx. Then I tried to find the bottleneck with xhprof. The xhprof result shows that in some requests (not for everyone), the fastcgi_finish_request function costs more than 80% of the total execution time. It is very strange.

Click to view full graph output from xhprof

Click to view form output from xhprof

Used Versions:

php: 5.3.8

nginx: 1.0.10

xhprof: built from its github source

Why does the fastcgi_finish_request function take so long? And how can I avoid this?

+4
source share
1 answer

At php-fpm.org:

fastcgi_finish_request () is a php function that stops response output. The web server immediately begins to transmit the response “slowly and sadly” to the client, and php at the same time can do a lot of useful things in the context of the request, such as saving a session, converting downloaded videos, processing all kinds of statistics, etc.

I have not used fastcgi_finish_request() myself, but if time is up, the server should send back the response received so far, it is considered the "runtime" for this method in the PHP script; it seems pretty clear why this function "consumes" so much time, because it depends on your network connection to the server and client (for example, ping).

Does runtime change when using the local development environment?

0
source

All Articles