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

Brian C. Fertig brian at planet-telecom.com
Tue Aug 9 08:18:20 MST 2005


Instead of writing your own you could use ours.. 


http://phpagi.sf.net

It easily allows you to write a PHP application that can
interact with Asterisk


..o-------------------------------------------------------o.
Brian Fertig
NOC/Network Engineer
Planet Telecom, Inc.


-----Original Message-----
From: asterisk-dev-bounces at lists.digium.com
[mailto:asterisk-dev-bounces at lists.digium.com] On Behalf Of Lambert
Sent: Tuesday, August 09, 2005 3:02 AM
To: asterisk-dev at lists.digium.com
Subject: [Asterisk-Dev] AGI-PHP, variable values are not showing

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


_______________________________________________
Asterisk-Dev mailing list
Asterisk-Dev at lists.digium.com
http://lists.digium.com/mailman/listinfo/asterisk-dev
To UNSUBSCRIBE or update options visit:
   http://lists.digium.com/mailman/listinfo/asterisk-dev


This email was scanned by:  Mcafee GroupShield
---------------- CONFIDENTIAL DISCLAMER ----------------
All information provided in this email is considered confidential
and proprietary of Planet Telecom, Inc. and Telecenter Inc.
Use of this information by anyone other than the recipient or 
sender will be considered in breach of agreement.



More information about the asterisk-dev mailing list