<div>Dear All,</div>
<div> </div>
<div>Never Mind, I have solved the problem. It seems that you should clear the buffer for any 'waiting' response or else you will be getting an empty '200 result=1' response. So be sure to read, before you write in php agi script to ensure that you will get a proper response.
</div>
<div> </div>
<div>Regards,</div>
<div>Kengie<br><br> </div>
<div><span class="gmail_quote">On 12/13/05, <b class="gmail_sendername">Kenige Ho</b> <<a href="mailto:kengiepanda@gmail.com">kengiepanda@gmail.com</a>> wrote:</span>
<blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">
<div>Dear All,</div>
<div> </div>
<div>I am trying to get a variable via AGI "GET VARIABLE XXXX", but using AGI DEBUG I actually do see the variable get return but somehow my retrieving the variable via php. I don't get the value of the variable. Below is my code and my results. Please help. thank you.
</div>
<div> </div>
<div>Coding:</div>
<div>
<p>#!/usr/bin/php -q<br><?php<br>ob_implicit_flush(true);<br>set_time_limit(6);<br>$in = fopen("<a>php://stdin","r")</a>;<br>$stdlog = fopen("/var/log/asterisk/my_agi.log", "w");
</p>
<p>// toggle debugging output (more verbose)<br>$debug = false;</p>
<p>// Do function definitions before we start the main loop<br>function read() {<br> global $in, $debug;<br> $input = str_replace("\n", "", fgets($in, 4096));<br> if ($debug) fputs($stdlog, "read: $input\n");
<br> return $input;<br>}</p>
<p>function errlog($line) {<br> global $err;<br> echo "VERBOSE \"$line\"\n";<br>}</p>
<p>function write($line) {<br> global $debug;<br> if ($debug) fputs($stdlog, "write: $line\n");<br> echo $line."\n";<br>}</p>
<p>// parse agi headers into array<br>while ($env=read()) {<br> $s = split(": ",$env);<br> // $agivar[str_replace("agi_","",$s[0])] = trim($s[1]);<br> // errlog($s[0].",".$s[1]);
<br> $agivar[$s[0]] = trim($s[1]);<br> if(($endid.phpv=="") || ($env=="\n")) {<br> break;<br> }<br>}</p>
<p><br>// main program<br>echo "VERBOSE \"fone-check\"\n";<br>$tmp = "GET VARIABLE xxxxx";<br>write($tmp);<br>errlog("Temp Var is " . $tmp);<br>$result = read();<br>errlog("Before Strip Result is " . $result);
<br>$result = trim(ereg_replace("200 result=1","",$result));<br>$result = trim(ereg_replace("\(","",$result));<br>$result = trim(ereg_replace("\)","",$result));<br>
errlog("After Strip Result is " . $result);</p>
<p>// clean up file handlers etc.<br>fclose($in);<br>fclose($stdlog);</p>
<p>exit;<br>?></p></div>
<div>Results:</div>
<div>AGI Debugging Enabled<br>AGI Tx >> agi_request: fone-check.agi<br>AGI Tx >> agi_channel: SIP/1234-adda<br>AGI Tx >> agi_language: en<br>AGI Tx >> agi_type: SIP<br>AGI Tx >> agi_uniqueid:
1134460079.22<br>AGI Tx >> agi_callerid: 1234<br>AGI Tx >> agi_calleridname: 1234<br>AGI Tx >> agi_callingpres: 0<br>AGI Tx >> agi_callingani2: 0<br>AGI Tx >> agi_callington: 0<br>AGI Tx >> agi_callingtns: 0
<br>AGI Tx >> agi_dnid: 1233<br>AGI Tx >> agi_rdnis: unknown<br>AGI Tx >> agi_context: test<br>AGI Tx >> agi_extension: 1233<br>AGI Tx >> agi_priority: 11<br>AGI Tx >> agi_enhanced: 0.0
<br>AGI Tx >> agi_accountcode: test<br>AGI Tx >> <br>AGI Rx << VERBOSE "fone-check"<br> fone-check.agi: fone-check<br>AGI Tx >> 200 result=1<br>AGI Rx << GET VARIABLE fone<br>AGI Tx >> 200 result=1 (555555)
<br>AGI Rx << VERBOSE "Temp Var is GET VARIABLE fone"<br> fone-check.agi: Temp Var is GET VARIABLE fone<br>AGI Tx >> 200 result=1<br>AGI Rx << VERBOSE "Before Strip Result is 200 result=1"
<br> fone-check.agi: Before Strip Result is 200 result=1<br>AGI Tx >> 200 result=1<br>AGI Rx << VERBOSE "After Strip Result is "<br> fone-check.agi: After Strip Result is <br>AGI Tx >> 200 result=1
</div>
<div> </div>
<div> </div>
<div>Regards,</div>
<div>Kengie</div></blockquote></div><br>