Forum Moderators: coopster

Message Too Old, No Replies

Tracking/killing process called from php script

         

wheel

1:37 am on Aug 6, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I've got a php program that accepts inputs from the web. It then uses those inputs to call a third party cgi program, basically a compiled black box. The third party cgi returns some results, our php program does some stuff to those results and outputs it.

Sounds fine, except that somewhere along the way once in a while something hangs and I end up with processes bogging down my server. To date working with my programmer and the programmer from the cgi program, we've been unable to point fingers as to where the problem is :).

What I'd like to do is from the php program, log all calls to the cgi program, including the start time. At the same time, every time the php program is run, check the log files for any instances of the cgi program running that is older than say 30 seconds. If it sees such an instance, log the instance in a seperate location and the kill the process.

My developer is objecting, saying he doesn't think we an do it that way (and I don't disagree - but it would be great if someone did :) ).

Is there any way, when a php program calls an external compiled cgi program, to track that process before or at the same time as the cgi program is called? And then more importantly, is there any way to later use that information to kill that process?

I suppose we could do something like call the command line 'ps aux' and parse that somehow but that seems cludgy and prone to error.

eelixduppy

2:43 am on Aug 6, 2008 (gmt 0)



You'd definitely have to run a command through the comnmand line to stop the process. As far as tracking the calls to these scripts, I am not sure exactly how you are going to implement this. If multiple instances of this CGI program are running at the same time, you'd have to kill the process based on the PID not the name itself. Seems to me to be more than it's worth.

As far as the script hanging in the first place, I'd definitely look at your CGI program. PHP will hang if this is hanging.