Asterisk & PHP AGI

Hello everyone,

I’m newbie with asterisk and if you have time, please advice me. I want to run php script, for example I want to analyse some conditions and every time for every condition I set variable, for examle $call. Then I want to send variable $call into dialplan, and for every value of $call to do something, if $call is 1, Dial,…or if is not, hangup…


First I’d install this:

Look for the demos for examples.

Yes, I know how to install everything, and I have it. My problem is syntax and logic how to past variable to Asterisk and to work something with it…

There are example scripts in the contrib/scripts directory, in the source distribution.

Use: Set_Variable(“yourvariable”,“yourvalue”), then in your dialplan use it calling the name “yourvariable”, and thats all.

$mcount=3; $agi->Set_Variable("count","${mcount}");

then in the dialplan:

.... same => n, NoOP( "the result of my count is ${count}") .....

Thank you all ! I will test it today, I hope without problems:) Or I will contact you again…thx once more

Unfortunately, I have problem.
In php script I set variable

$my = 1;
$agi -> set_variable(“myvar”,"${my}");

Then in dialplan I wrote :

exten => XXX,1,Wait(1)
exten => XXX,2,AGI(script.php)
exten => XXX,n,NoOp(“the result is ${myvar}”)
exten => XXX,n,GotoIf($["${myvar}" = “1”]?yes:no)
exten => XXX,n(yes),Dial(SIP/XXX)
exten => XXX,n(no),Dial(SIP/XXX)
exten => XXX,n,Hangup()

But I got nothing in variable :frowning:

Executing […] NoOp(“SIP/XXX-…”, ""the result is “”) in new stack

What is the result of enabling AGI debugging in the Asterisk CLI?