[Asterisk-Dev] AGI-PHP, variable values are not showing

Lambert lambert at mindragon.com
Tue Aug 9 00:02:17 MST 2005


im having some trouble with AGI-PHP, the script runs with no errors shown
on CLI, i tried to save logs to see if the script is actually running and
it is, but i cant seem to set any value to any variable, i tried using
those variables in NoOp but none of those values are showing, anyone? 

heres the PHP script i used

#!/usr/bin/php -q
<?
ob_implicit_flush(false);
set_time_limit(5);
error_reporting(0);

$stdin	= fopen("php://stdin",	"r");
$stdout	= fopen("php://stdout",	"w");
$stdlog	= fopen("/var/log/asterisk/mdi_agi.log",	"a");
$debug	= true;

// get AGI response
///////////////////
function read()
	{ 
	global $stdin, $debug, $stdlog; 
	
	$input = str_replace("\n", "", fgets($stdin, 4096)); 
	if ($debug) 
		fputs($stdlog, "read: $input\n"); 
	
	return $input; 
	} 

// send command to AGI
//////////////////////
function write($AGI)
	{
	global 	$stdout, $debug, $stdlog;

	fputs($stdout, "$AGI \n");
	fflush($stdout);

	if ($debug) 
		fputs($stdlog, "write: $line\n");
	}

// error/debug logs
///////////////////
function errlog($log)
	{
	$global	$debug, $stdlog;
	if ($debug)
		fputs($stdlog, "debug: $log\n");
	}

// get AGI headers
//////////////////
while (!feof($stdin))
	{
	$temp	= fgets($stdin);
	$temp	= str_replace("\n","",$temp);
	$s		= explode(":",$temp);
	$agivar[$s[0]] = trim($s[1]);

	if (($temp == "") || ($temp == "\n")) 
		break;
	}

errlog("Connect [ " . $agivar["agi_callerid"] . "]");

write("SET VARIABLE ACCOUNTCODE \"someaccountcode\"");
write("SET VARIABLE CALLERID \"somecallerid\" <12345678>");
write("SET VARIABLE TEST_VARIABLE1 \"testvariable1\"");
write("SET VARIABLE TEST_VARIABLE2 100");

mysql_free_result($result);
mysql_close($dbcon);

// clean up file handlers
/////////////////////////
fclose($stdin);
fclose($stdout);
fclose($stdlog);

errlog("Close [ " . $agivar["agi_callerid"] . "]");

exit;
?>





More information about the asterisk-dev mailing list