简体   繁体   中英

Recursion in phpagi script of asterisk server

I am using this in extension file which execute the my phpagi script:-

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

And this in my phpagi script:-

#!/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. There is an error in CLI script:-

AGI Script a.php completed, returning 4

You can't start AGI inside AGI.

Reason: AGI is simple stdin/stdout interface(read doc)

So first AGI connect to asterisk,read info from STDIN,send to 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).

In your case you also can use GOTO and set variables for new script.

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

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