[resolved] AGI and PHP

I’m beginning to use AGI & PHP. Could someone tell me how to pass variables to/from PHP from within the dial plan?

Hi,

I am using Asterisk 1.2.12. This is my dialplan in AEL, convert it to .conf if you want:

_X. => {
Set(ALLOWED=‘0’);
AGI(CheckLMenabled.agi);
if("${LMENABLED}"= “1”) {

            } 

This is CheckLMenabled.agi: (edited for brevity)

#!/usr/bin/php -q

<?php set_time_limit(60000); ob_implicit_flush(false); //error_reporting(0); if(!defined('STDIN')) { define('STDIN', fopen('php://stdin','r')); } if(!defined('STDOUT')) { define('STDOUT', fopen('php://stdout','w')); } if(!defined('STDERR')) { define('STDERR', fopen('php://stderr','w')); } fwrite(STDERR," STARTING..."); //retrieve all Asterisk variables from Asterisk while(!feof(STDIN)) { $temp = trim(fgets(STDIN,4096)); if(($temp=="")||($temp=="\n")) { break; } $s = split(":",$temp); $name = str_replace("agi_","",$s[0]); $agi[$name]=trim($s[1]); } foreach($agi as $key=>$value) { fwrite(STDERR,"--$key=$value\n"); fflush(STDERR); } fwrite(STDERR,"CALLERID== $agi[callerid]"); fflush(STDERR); fwrite(STDOUT,"SET VARIABLE LMENABLED 1"); fflush(STDOUT); So you can see that I set a variable LMENABLED in the AGI and use it in the dialplan. You can also set a variable in the dialplan and use it in AGI. To use channel variables use: $agi[] HTH

I figured it out - the first line in the PHP scrip needs to be as follows:

#!/usr/bin/php --q

I was previously using only one dash, as in:

#!/usr/bin/php -q