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?

  • Can you run vmstat 1 while doing the tests, and check whether any of those numbers change during the delays?
    – thrig
    Nov 6, 2015 at 22:55
  • 2
    It might help to tell us what the PHP does: network accesses, writes to files, DB access, etc.
    – user732
    Nov 6, 2015 at 23:40
  • Yes it was an unused firebird db access, after disabling it the delay dissapeared, thanks for your help
    – Chico3001
    Nov 7, 2015 at 5:33

1 Answer 1


A consistent 8 seconds implies that some potentially long-running procedure has a timeout set. Without knowing what the PHP code does, I'm going to guess that you've got a DNS time. If the PHP is doing some network I/O or something, it probably triggers a DNS lookup. Every once in a while, you're seeing a DNS query time out and the PHP going on to do whatever it does in that eventuality.

The only place I can see that DNS timeouts are set is in /etc/resolv.conf, or maybe when the resolver(3) code in GNU libc gets compiled. Unfortunately, the man page for resolv.conf claims that a 5 second timeout is the compiled-in default, so I can only say I'm guessing at this.

  • You where right... it wasn't DNS but a firebird db extension that wasn't used in the script so it was hanging the script until the timeout completed
    – Chico3001
    Nov 7, 2015 at 5:31

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .