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 (  => 1446841239.1471  => 0.0581  => 0.0589  => 0.0564  => 8.0531  => 0.0574  => 0.0621  => 8.0582  => 0.0548  => 8.0457  => 0.0755  => 8.0555  => 0.0512  => 8.0447  => 0.062  => 8.0905  => 0.0602  => 8.0556  => 0.0582  => 8.0492  => 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?