A problem with returned variables in AGI

I have a weird problem with my return values not being what I expect from a Queue command in a php agi script…

[code]ob_implicit_flush(true);
set_time_limit(6);
$in = fopen(“php://stdin”,“r”);
$stdlog = fopen(“/var/log/asterisk/agi.log”, “w”);

// toggle debugging output (more verbose)
$debug = true;

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

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

write("EXEC Queue ".$val);
$appReturn = read();
echo “VERBOSE "RETURN VALUE >>>>> “.$appReturn.”" \n”;
[/code]

With agi debug on I see the ‘correct’ variable sent back but that’s not what my read() function sees.

Example debug output:

Any ideas?

bump

Still have issues… anyone got any ideas?

I use:

 $agi->agi_exec("SET VARIABLE VARNAME UNK")

where VARNAME is the variable I am setting and UNK is the value.

That’s ok for setting variables but I want to read the return value of a function, in this case Queue(). With AGI debug on I can see that Asterisk is returning the correct value to the AGI script (either -1, 0 or 1) but when I then try and read standard input, I get an incorrect value… it is always result=1 :unamused: