York.Gu
York.Gu

Reputation: 45

function fastcgi_finish_request cost most of the executing time

I built a site with yii + php-fpm + nginx. Then I tried to find the bottleneck with xhprof. The result of xhprof shows that in some requests(not all), function fastcgi_finish_request cost over 80% of all the executing time. It's very strange.

Click to view the full graph output from xhprof

Click to view the form output from xhprof

the versions I use are:

php: 5.3.8

nginx: 1.0.10

xhprof: built from its github source

Why does the function fastcgi_finish_request take so much time? And how should I avoid this?

Upvotes: 4

Views: 1419

Answers (1)

schmunk
schmunk

Reputation: 4708

From the php-fpm.org page:

fastcgi_finish_request() is a php feature, that stops the response output. Web server immediately starts to transfer response "slowly and sadly" to the client, and php at the same time can do a lot of useful things in the context of a query, such as saving the session, converting the downloaded video, handling all kinds of statistics, etc.

I haven't used fastcgi_finish_request() myself yet, but if the time, the server needs to send back the response output made so far, counts as "execution time" for this method in the PHP script; it seems pretty clear, why this function "consumes" so much time, because it depends on your server and client network connection (eg. ping).

Does the execution time vary when using a local dev-environment?

Upvotes: 1

Related Questions