问题
I'm trying to find which php scripts are overloading my server's cpu, but by the results of top I cannot see specifically which one it is. Is there any way to relate the top processes with the script causing the load ? or is there any other way to debug this?
PID   USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
19810 apache    15   0  364m  44m 5004 S 15.2  0.3   0:02.39 /usr/sbin/httpd
19827 apache    15   0  364m  44m 4752 S 15.2  0.3   0:01.58 /usr/sbin/httpd
19599 apache    18   0  365m  45m 5012 D 12.3  0.3   0:08.83 /usr/sbin/httpd
19900 apache    15   0  361m  41m 4912 S 11.6  0.3   0:00.37 /usr/sbin/httpd
19907 apache    15   0  360m  40m 4744 S 11.6  0.3   0:00.56 /usr/sbin/httpd
    回答1:
You can enable mod-status. Mod status show requests in real time with a lot a informations about them, including the CPU usage, the matching pids etc...
回答2:
you can also use xdebug to profile your code.
来源:https://stackoverflow.com/questions/8464327/detect-which-script-causes-server-overload-apache-php