简体   繁体   English

PHPAgi流程中的Asterisk AGI

[英]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 我为我的星号11.3.0在php中创建了一个agi,当我在服务器中使用ps ux时,几乎没有agi调用卡在队列中
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 编号为0:00 /usr/bin/php -q /var/lib/asterisk/agi-bin/php/myagi.php 954332 190053所有过程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. 如果来自未知号码的电话,我需要知道如何调试我的agi。

My AGI Script 我的AGI脚本

#!/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 要调试agi,您需要从ssh执行以下操作

1) Stop asterisk deamon 1)停止星号守护进程

  asterisk -rx "core stop now"

2) Start asterisk in console(not detach) and start agi debug - all error will be shown 2)在控制台中启动星号(不分离)并启动agi调试-将显示所有错误

  asterisk -vvvvgc
  agi set debug on
  core set verbose 5

3) Check now. 3)现在检查。 You have see all conversation between asterisk and your AGI script and all errors generated by script. 您已经看到了星号和AGI脚本之间的所有对话以及该脚本生成的所有错误。

If still not help, also try "core set debug 5", but output will be hard to understand. 如果仍然没有帮助,也可以尝试“ core set debug 5”,但是输出将很难理解。

You ignore the SIGHUP signal when the channel is hung up ( Call Disconnect ). 通道挂起时,您可以忽略SIGHUP信号( 呼叫断开 )。

Add g to the Dial: 在表盘上添加g

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 AGI调试

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 连接到星号(Verbosity 3): asterisk -rvvv

Use the CLI command agi show commands to list available agi commands. 使用CLI命令agi show命令可以列出可用的agi命令。
*CLI> agi show

Watch AGI and your debug messages on the Asterisk CLI. 在Asterisk CLI上观看AGI和您的调试消息。
*CLI> agi set debug on

You could set your AGI Script verbose, when "Unknown" is given and log to a file: 当给出“未知”时,您可以将您的AGI脚本设置为冗长并登录到文件:

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);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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