EAGI Not Detecting Hangup

Hi,

I’m currently having an issue with an EAGI script not receiving a SIGHUP from asterisk when the call is hung up. I’m using asterisk 1.8.4.2. Here is my dialplan

[sip-incoming-default]
exten => _X.,1,noop(>>>> received call)
exten => _X.,n,set(AGISIGHUP=yes)
exten => _X.,n,EAGI(test.php)

Here is a stripped down version of the code that recreates the problem. I’m setting the variable instead of just calling exit because the bigger script has to do cleanup functions and things like that. The problem is that the only way i can kill this script is to do -9 as it’s not seeing any of the other signals.

#!/usr/bin/php -q
<?php

declare(ticks=1);
$myvar=0;
function sig_handler($signo)
{

        switch($signo) {
            case SIGTERM:
                $myvar = 1;
                break;
            case SIGINT:
                $myvar = 1;
                break;
        case SIGUSR1:
                $myvar = 1;
                break;
        case SIGHUP:
                $myvar = 1;
                break;
        case SIGQUIT:
                $myvar = 1;
                break;
        }

  return;
}
  pcntl_signal(SIGTERM, "sig_handler");
  pcntl_signal(SIGUSR1, "sig_handler");
  pcntl_signal(SIGHUP,  "sig_handler");
  pcntl_signal(SIGINT, "sig_handler");
  pcntl_signal(SIGQUIT, "sig_handler");
  printf ("sleeping now\n");
  while(1) {
        print $myvar;
        if($myvar==1)
        {
          exit;
        }
  }

?>

I’m really at a loss as to how to fix this. If you could shed some light on a fix it would be greatly appreciated.

Thanks