Accessing Dialplan variables in AGI script

Hello all,

I have been trying to do the following with minimal success:

A portion of my dialplan is as under

exten => s,1,Answer
exten => s,2,DigitTimeout,5
exten => s,3,ResponseTimeout,10
exten => s,4,Set(poll_id=1)
exten => s,5,Background(/srv/www/htdocs/callmanager/audio/intro)
exten => s,6,Goto(Poll1-1,s,1)

exten => s,1,Background(/srv/www/htdocs/callmanager/audio/ques1)
exten => 1,1,Set(ques_1=1)
exten => 1,2,Goto(Poll1-2,s,1)
exten => 2,1,Set(ques_1=2)
exten => 2,2,Goto(Poll1-2,s,1)
exten => #,1,Set(ques_1=3)
exten => #,2,Goto(Poll1-2,s,1)
exten => *,1,Goto(Poll1-1,s,1)

exten => s,1,Background(/srv/www/htdocs/callmanager/audio/ques2)
exten => 1,1,Set(ques_2=1)
exten => 1,2,Goto(hangup1,s,1)
exten => 2,1,Set(ques_2=2)
exten => 2,2,Goto(hangup1,s,1)
exten => #,1,Set(ques_2=3)
exten => #,2,Goto(hangup1,s,1)
exten => *,1,Goto(Poll1-2,s,1)

exten => s,1,agi,store.php
exten => s,2,Background(/srv/www/htdocs/callmanager/audio/outro)
exten => s,3,Hangup

Also the store.php has the following contents

#!/usr/bin/php -q
$in = fopen("php://stdin","r");

$stdlog = fopen("/var/log/asterisk/my_agi.log", "w");
// toggle debugging output (more verbose)
 $debug = false;

// Do function definitions before we start the main loop
function read() {
  global $in, $debug;
  $input = str_replace("\n", "", fgets($in, 4096));
  if ($debug) fputs($stdlog, "read: $input\n");
  return $input;

function errlog($line) {
  global $err;
  echo "VERBOSE \"$line\"\n";

function write($line) {
  global $debug;
  if ($debug) fputs($stdlog, "write: $line\n");
  echo $line."\n";

// parse agi headers into array
while ($env=read()) {
  $env = str_replace("\"","",$env);
  $s = split(": ",$env);
  $agi[str_replace("agi_","",$s[0])] = trim($s[1]);
     if (($env == "") || ($env == "\n")) {

write("GET VARIABLE poll_id");
 $poll_id = read();
echo "VERBOSE \"First\"\n";
echo "VERBOSE \"$poll_id\"\n";


All that i am trying to do is to set the variables (ques_1 and ques_2) in the dialplan and access them in agi through store.php script. The problem that i am facing here is that when i output the contents of ques_1 variable in the store.php script, it gives me the following:

store.php: 200 result=1

It is supposed to give me a value too after “200 result=1” but i dont get any value. Why is this happening? Is there any option in the dialplan that i need to turn on? I tried the same thing with global variables too but didn’t succeed.

Any kind of pointers will be appreciated.