Problem with PHPAGI "get variable dialstatus"

Hello !

Well i am using asterisk 1.4 and PHPAGI 2.
so in my PHP script i am using all the functions of PHPAGI.
I have the same problems that described here : … d0401a60b1

But no real solution to it.

So in my script here is my code :

[code]$agi->write(“EXEC DIAL SIP/$num_appele|5|t,r”);
$ret = $agi->evaluate(“GET VARIABLE DIALSTATUS”);


evaluate will execute the command “GET VARIABLE STATUS” and will recover the answer from that command.

So in my CLI i put “AGI DEBUG” and here is the result :

AGI Rx << GET VARIABLE DIALSTATUS AGI Tx >> 200 result=1 (NOANSWER) AGI Rx << 200 result=0

The correct result is indeed 200 result=1 (NOANSWER) that is what is returned after putting the previous command.
But when i want to use the message returned and collected by the function evaluate() i get 200 result=0 !!!

Why dont i get 200 result=1 (NOANSWER)…

function evaluate short version :

[code]function evaluate($command)
$broken = array(‘code’=>500, ‘result’=>-1, ‘data’=>’’);

  // write command
  if(!@fwrite($this->out, trim($command) . "\n")) return $broken;

  // Read result.  Occasionally, a command return a string followed by an extra new line.
  // When this happens, our script will ignore the new line, but it will still be in the
  // buffer.  So, if we get a blank line, it is probably the result of a previous
  // command.  We read until we get a valid result or asterisk hangs up.  One offending
  // command is SEND TEXT.
  $count = 0;
    $str = trim(fgets($this->in, 4096));
  } while($str == '' && $count++ < 5);
    return $str;


function evaluate long version : … html#a1493

I hope you can help me understand why i am not getting what i want :wink:

thanks and have a nice day !


any answer ??? :cry:


You do $agi->write() to send a command to AGI, then $agi->evaluate() to fetch the variable into $ret, but then you send the value of $ret back to AGI again?

Thanks to your answer :wink:

To answer the major question :
the script is trying to get the result of the variable DIALSTATUS.
Which could be for example : 200 result=1 (NOANSWER)

the write() function does only a print. (ok not a very useful function…:wink: )

function write($line) { echo $line."\n"; }

  • At first i dial the extension that i want to call. (the first write())

  • Then i want to get the result of the variable DIALSTATUS : evaluate(“GET VARIABLE DIALSTATUS”);
    This function evaluate does :
    –> a print of the command into stdout (for me it is $this->out)
    –> get the result of that command which should appear in stdin ($this->in)
    –> return this result ($str)

  • Finally write to the CLI the returned result : write($ret). this is to print to the screen the result (my debug solution).

The related code :

[code]$agi->write(“EXEC DIAL SIP/$num_appele|5|t,r”);
$ret = $agi->evaluate(“GET VARIABLE DIALSTATUS”);


So when i send the command GET VARIABLE DIALSTATUS this happens :


My goal is to get that last line but when i do it (with the code i just explained), i only get :

It looks like $agi->write() is to send a command to the AGI, but when you read the result back, you are sending that output back to the AGI as a command - it is not going (I don’t think) to write the result to the screen - and scripts like this are not interactive are they? If not, there is no screen to write to. If the script IS interactive, you should be using 'print “$res\n” or somesuch, no?

ok but in the next part of my screen i need to know if the call was answered or not (unavailable, no answer…). Depending of each case i’ll do a different action.
So how can i get this information, because right now i can’t get it ?

did you have any trouble in your php script with that function ?

parse the variable $ret and look for NOANSWER?

already tried that in many way. :smile:
That is the reason why i wanted to know the real content of $ret and did a print to the AGI.
and the result is : “200 result=0” …