Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Long PHP execution for high latency(?) users

Tags:

php

apache

I recently added PHP execution times to my visitor logs to spot possible issues in the code or databases. Time is measured as microtime() difference between beginning and end of the script.

Average execution time (including my own tests on debug version of the site) is 2-15ms. Then I randomly see +300ms execution for some users. Those are likely caused by load spikes, uncached database queries or filesystem access.

What I can't understand are every now and then appearing users with 5-30 second(!) execution time. Based on my tests those appear on seemingly random pages and and there isn't any request spikes on the access logs for those times, nor is there anything on code or database queries that could possibly cause this slow performance. 90% of those requests come from China and seem to be some kind of crawlers or bots.

So: Can latency affect execution time of a PHP script? Is PHP execution halted while previous buffer is sent to user?

I found this other thread with seemingly similar matter but there was no answer: PHP's execution time changes based upon internet/connection latency?

EDIT:
I ended up increasing PHP output_buffering from 4k to 128k bytes. Now the typical execution time dropped to 2-6ms and there are no more random ridiculously long timings.

like image 346
MiikaH Avatar asked Nov 20 '12 10:11

MiikaH


1 Answers

I think that latency can affect PHP execution time, depending on the server configuration, particularly output_buffering and implicit_flush.

Also, there is some functions like gethostsbyaddr that can slow down a PHP script.

Maybe you can use XDebug to generate execution trace and see the "timeline" of the execution of a script.

like image 159
Vince Avatar answered Oct 04 '22 23:10

Vince