[asterisk-biz] Asterisk 1.4.22.1 and zombies

Jared Smith jsmith at digium.com
Wed Jan 21 10:16:52 CST 2009


On Wed, 2009-01-21 at 15:54 +0100, Sabine Jordan wrote:
> The defunct processes are from the application but these proceses are
> children of the asterisk process.

[snip]

> Any more ideas would be appreciated. Thank you in advance.

One of the things that can cause problems with AGI scripts is if your
AGI script doesn't properly listen for a SIGHUP signal from the
operating system, and react accordingly.  When the caller hangs up,
Asterisk ends up sending the SIGHUP signal to your application, and if
your application doesn't listen for that signal and shut down, it can
obviously become defunct.

Unfortunately, with PHP, this is a little more difficult than it ought
to be.

I found this little nugget of knowledge a long time ago on one of the
mailing lists or forums (but unfortunately didn't keep track of where I
found it), and it's been useful for me.  Your mileage may obviously
vary.

You must have the pcntl module for PHP installed for this to work
properly.

<?php
declare(ticks=1);
// don't buffer output... flush it immediately
ob_implicit_flush(true);

function sig_handler($signo){
// the code in this function will execute when the caller hangs up
// and Asterisk sends the SIGHUP signal.
//
// for example, you could have your program write a database log
// and/or close any existing connections to the outside world, and
// then exit
}

// this tells PHP which function to run when it receives SIGHUP
// from Asterisk
pcntl_signal(SIGHUP, "sig_handler");

// MAIN PROGRAM GOES HERE

?>

Like I said earlier, this may or may not solve your problem, but it's
worked well for me with PHP AGI scripts.


-- 
Jared Smith
Digium, Inc. | Training Manager 






More information about the asterisk-biz mailing list