I'm programming a PHP web page and I started seeing some strange behavior on my computer, at some point apache / php takes to long to show the webpage on the browser (8 secs), first i thought it was my application that had a bug, so i made a debug function to keep track of the time needed to finish my script, but when i started reloading the page several times (pressing F5) i noticed that it wasn't my script but some other process that stalls apache (or php, or mysql) and then releases it because pressing F5 several times show that sometimes the script finishes fast and sometimes it takes a lot:
[time_start] => Array
(
[0] => 1446841239.1471
[1] => 0.0581
[2] => 0.0589
[3] => 0.0564
[4] => 8.0531
[5] => 0.0574
[6] => 0.0621
[7] => 8.0582
[8] => 0.0548
[9] => 8.0457
[10] => 0.0755
[11] => 8.0555
[12] => 0.0512
[13] => 8.0447
[14] => 0.062
[15] => 8.0905
[16] => 0.0602
[17] => 8.0556
[18] => 0.0582
[19] => 8.0492
[20] => 0.0551
)
Each step is the same script running after F5 is pressed, and it should take always the same time, but sometimes it takes 8 seconds to finish, and that bugs me because when its stalled it ALWAYS takes about 8 seconds
So the question is, any ideas on how can I find the process that is stalling my script?
Ps.- Im running a lot of things on the foreground because its my personal computer, but even when i only use the browser with no other application running it still hangs so it has to be something running on the background, how can i find it?
vmstat 1
while doing the tests, and check whether any of those numbers change during the delays?