Tower
Tower

Reputation: 102945

How to find out what makes my PHP application to hang the Apache server?

I am running into an issue where my PHP application hangs sometimes and the Apache server takes long to restart. Is there some way to determine what might cause this hang up?

Upvotes: 3

Views: 4032

Answers (1)

huelbois
huelbois

Reputation: 7012

If you are on a linux server, a heavy solution could be to strace your Apache processes.

It will provide you with all the system calls (and parameters) done by the Apache processes, and eventually find what could be hanging (or find out that your script tries to get a resource - eg a file - that it can't read, open a socket and wait until the timeout, etc).

You invoke it like that:

strace -f -p pid

pid being the pid of the process you want to trace.

In your case, I recommend changing the configuration of your Apache server (if necessary) to have a little number of servers spawned. You fetch their pids with a regular ps command. Then you can strace several pids at the same time, by adding -p pid1 -p pid2 etc. You can also use -o filename and -ff to have each process strace written to filename.pid files. Then you run your HTTP request. The process that has processed your request will be in the biggest .pid file.

Also use -s size to specify the length of text to capture, for example in 'write' syscalls, or else you might miss interesting information.

It can be hard to read, but can provide really helpful information. I use it frequently for desperate situations !

Upvotes: 8

Related Questions