简体   繁体   中英

Asterisk AGI in PHPAgi process

I have create an agi in php for my asterisk 11.3.0 and i have few agi calls stuck in queue when i use ps ux in my server it shows
6:42 /usr/bin/php -q /var/lib/asterisk/agi-bin/php/myagi.php Unknown 190090

Many processes like this stuck in queue.

All process with number like 0:00 /usr/bin/php -q /var/lib/asterisk/agi-bin/php/myagi.php 954332 190053

I need to know how do i debug my agi if call from unknown number.

My AGI Script

#!/usr/bin/php -q
<?php
pcntl_signal(SIGHUP, SIG_IGN);
require('phpagi/phpagi.php');

$agi                = new AGI();

$calleridnum    = $agi->request['agi_callerid'];
$callerid       = $agi->request['agi_callerid'];
$callidname     = $agi->request['agi_calleridname'];
$phoneno        = $agi->request['agi_dnid'];
$channel        = $agi->request['agi_channel'];
$uniqueid       = $agi->request['agi_uniqueid'];

if(substr($phoneno,0,3)==011)
{
    $phoneno = substr($phoneno, 3);
}

$URL = '12121@mysip.abc.com';

$dialstr = "SIP/" . $URL;

$res = $agi->exec("DIAL $dialstr");

$dialstatus = $agi->get_variable("DIALSTATUS");
$answeredtime = $agi->get_variable("ANSWEREDTIME");


if($dialstatus['data'] != "ANSWER")
{
    //No answer
}
if($dialstatus['data'] == "ANSWER") 
{
    $agi->verbose("I am in Cutting Balance!!");
}
savecdr($URL,"$callerid", $phoneno, $trunk, $dialstatus['data'], $answeredtime['data'], $PerMinuteCharges,$callstart,$TriggerCharge,$OID,$callidname,$IP,$NodeID,$MinutesUsed,$TalkTime,$TTCut,$pTTRemain,$pHash[Expiry],$pMinTotal,$VOID);


$agi->hangup();

?>

To debug agi you need do following from ssh

1) Stop asterisk deamon

  asterisk -rx "core stop now"

2) Start asterisk in console(not detach) and start agi debug - all error will be shown

  asterisk -vvvvgc
  agi set debug on
  core set verbose 5

3) Check now. You have see all conversation between asterisk and your AGI script and all errors generated by script.

If still not help, also try "core set debug 5", but output will be hard to understand.

You ignore the SIGHUP signal when the channel is hung up ( Call Disconnect ).

Add g to the Dial:

g: Proceed with dialplan execution at the next priority in the current extension if the destination channel hangs up.

$agi->exec('DIAL', $dialstring.",30,g");

AGI Debug

You could print some debug messages in your Script:

// debug infos
$agi->verbose("before dial",3); 
// ...
$agi->verbose("Number: ".$argv[2]); 

Connect to Asterisk (with Verbosity 3) : asterisk -rvvv

Use the CLI command agi show commands to list available agi commands.
*CLI> agi show

Watch AGI and your debug messages on the Asterisk CLI.
*CLI> agi set debug on

You could set your AGI Script verbose, when "Unknown" is given and log to a file:

if ($argv[1] == "Unknown") {
  define ('VERBOSE', true);
} else {
  define ('VERBOSE', false);
}

if (VERBOSE) file_put_contents("/tmp/unknown.log", time().": ".$msg, FILE_APPEND | LOCK_EX);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM