简体   繁体   English

星号服务器的phpagi脚本中的递归

[英]Recursion in phpagi script of asterisk server

I am using this in extension file which execute the my phpagi script:- 我在执行我的phpagi脚本的扩展文件中使用它:

exten => s,n,Read(NUMBER,,4)
exten => s,n,agi(a.php,${CALLERID(num)},${NUMBER})

And this in my phpagi script:- 而这在我的phpagi脚本中:

#!/usr/bin/php -q 
<?php
require('phpagi.php');
$agi = new AGI();
$NUMBER = $argv[1];
$SSnNUMBER = $argv[2];
 ------Some Processing----------
$ttresult = $agi->get_data("beep",30000,4); 
$ttssn = $ttresult['result']; 
$agi->say_digits($ttssn); 
$agi->exec("AGI","a.php",$agi->request['agi_callerid'],"$ttssn");
?>

You can see i am using recursion in phpagi script, But this fails every time. 您可以看到我在phpagi脚本中使用递归,但是每次都失败。 There is an error in CLI script:- CLI脚本中有错误:-

AGI Script a.php completed, returning 4 AGI脚本a.php已完成,返回4

You can't start AGI inside AGI. 您无法在AGI中启动AGI。

Reason: AGI is simple stdin/stdout interface(read doc) 原因:AGI是简单的stdin / stdout接口(阅读文档)

So first AGI connect to asterisk,read info from STDIN,send to STDOUT. 因此,首先将AGI连接到星号,从STDIN读取信息,然后发送到STDOUT。

How you expect start script inside it? 您如何期望其中的启动脚本?

You can just use php exec system call, but you need care about initialization of AGI(it already consumend by your script) and about sending stdin/stdout to that process(using pipes or some other way). 您可以只使用php exec系统调用,但是您需要注意AGI的初始化(已被脚本消耗)和将stdin / stdout发送到该进程(使用管道或其他方式)。

In your case you also can use GOTO and set variables for new script. 您还可以使用GOTO并为新脚本设置变量。

exten => s,n(repeat),agi(a.php,${CALLERID(num)},${NUMBER})
exten => s,n,GotoIF($[ "${REPEAT}" == "YES" ]?repeat)

Change your script to 将脚本更改为

#!/usr/bin/php -q 
<?php
require('phpagi.php');
$agi = new AGI();
$NUMBER = $argv[1];
$SSnNUMBER = $argv[2];
 ------Some Processing----------
$ttresult = $agi->get_data("beep",30000,4); 
$ttssn = $ttresult['result']; 
$agi->say_digits($ttssn); 
$agi->set_variable("NUMBER","$ttssn");
$agi->set_variable("REPEAT","YES");
?>

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

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