0

Right now I'm dealing with a client's php based site that is somehow clogging up all of the available processes he has with his shared hosting provider. I'd like to prove to him exactly what and how many processes are being ran at a time when a specific index page is being loaded in a browser. I can see about 5 or 6 pop off at a time in top, but they all go away and come back so quickly I can't get a bead on any specific pid to trace.

Anyone have an idea of how I can anticipate the pid number I should be following to find out what his site specifically is doing?

b1kjsh
  • 123
  • 1
  • 4

2 Answers2

1

Use ps or pstree to find the parent pid for whatever you want to trace, I'm assuming it's probably apache? Then, use the -f option to strace so it follows all child pids too. Finally if you have a relatively recent strace you can just trace the process activity with -e trace=process.

Putting it all together, and assuming your apache parent process is pid 1234:

strace -o logfile.txt -f -e trace=process -p1234

should get you pretty close to where you want to go.

Phil Hollenback
  • 14,947
  • 4
  • 35
  • 52
  • That would work, but I need to figure out what pid I should be following. Shared Servers tend to have a bunch of open apache processes, I'm trying to figure out which one of those it's going to use so I can strace... – b1kjsh Nov 08 '11 at 07:55
  • I wonder if you can find the apache pid in a lockfile or logfile? – Phil Hollenback Nov 16 '11 at 17:29
1

I wonder if the following concept would be too slow (even if scripted) to catch the pid:

  1. Make inotifywait wait for specific index page access.
  2. Configure inotifywait to trigger

strace -o /tmp/wtf -f -e trace=process -p $(lsof -t /path/to/specific/index.php)

Or something similar. This was just a wild guess without actually trying above.

See also: XDebug and KCacheGrind.

Janne Pikkarainen
  • 31,852
  • 4
  • 58
  • 81
  • +1 for the XDebug mention. Trying to debug PHP with strace is going to be pretty painful. – Zoredache Nov 08 '11 at 08:32
  • Doesn't look like this server is configured with inotifywait, good idea though. the lsof trick is nice as well I'll have to give that a try. Edit: ah dang it, the lsof trick isn't working either. :( Edit2: actually that's my bad lsof trick does work thanks Janne :D – b1kjsh Nov 08 '11 at 09:48